@crewlethq/ui 0.190.2 → 0.192.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 +11 -3
- package/dist/AgentHandoffPanel/AgentHandoffPanel.d.ts +4 -1
- package/dist/AgentHandoffPanel/index.js +11 -7
- package/dist/AgentIdentity/index.js +8 -7
- package/dist/Announcer/index.js +2 -1
- package/dist/AppShell/index.js +4 -3
- package/dist/ArrangeFrame/index.js +3 -2
- package/dist/ArrangeList/index.js +7 -6
- package/dist/ArtifactBar/index.js +3 -2
- package/dist/ArtifactCard/index.js +6 -5
- package/dist/AvatarPicker/index.js +1 -1
- package/dist/Canvas/index.js +3 -2
- package/dist/CanvasBoard/index.js +5 -4
- package/dist/CanvasToolbar/index.js +4 -3
- package/dist/CharacterCount/index.js +3 -2
- package/dist/CheckGrid/index.js +6 -5
- package/dist/Checkbox/index.js +5 -4
- package/dist/ChipField/index.js +3 -2
- package/dist/ColorField/index.js +5 -4
- package/dist/Combobox/index.js +5 -4
- package/dist/CommandPalette/index.js +10 -8
- package/dist/CommentThread/CommentThread.d.ts +4 -1
- package/dist/CommentThread/index.js +11 -7
- package/dist/Composer/Composer.d.ts +7 -0
- package/dist/Composer/index.d.ts +1 -0
- package/dist/Composer/index.js +12 -6
- package/dist/{Composer-YO275MFX.css → Composer-YCD6UPMO.css} +3 -2
- package/dist/ConfirmField/index.js +5 -4
- package/dist/ConsequenceList/index.js +6 -5
- package/dist/DataGrid/index.js +7 -6
- package/dist/DataTable/index.js +8 -7
- package/dist/DataView/index.js +12 -10
- package/dist/Dictation/fake.d.ts +59 -0
- package/dist/Dictation/index.d.ts +8 -0
- package/dist/Dictation/index.js +17 -0
- package/dist/Dictation/labels.d.ts +4 -0
- package/dist/Dictation/machine.d.ts +126 -0
- package/dist/Dictation/microphone.d.ts +5 -0
- package/dist/Dictation/session.d.ts +31 -0
- package/dist/Dictation/slot.d.ts +69 -0
- package/dist/Dictation/types.d.ts +158 -0
- package/dist/Dictation/webSpeech.d.ts +13 -0
- package/dist/Dictation/webSpeechLocal.d.ts +9 -0
- package/dist/Dictation-MGLRANB4.css +141 -0
- package/dist/DocTabsEditor/index.js +6 -5
- package/dist/DurationField/index.js +6 -5
- package/dist/{Editor-FZOUNP6V.js → Editor-ZQUOI3WV.js} +5 -4
- package/dist/EmojiPicker/index.js +5 -4
- package/dist/GraphCanvas/index.js +4 -3
- package/dist/InlineEditor/index.js +3 -2
- package/dist/Input/index.js +4 -3
- package/dist/Kbd/index.js +2 -1
- package/dist/KeyValueRows/index.js +5 -4
- package/dist/LinkInterstitial/index.js +8 -7
- package/dist/ListInput/index.js +8 -6
- package/dist/MemberPicker/index.js +6 -5
- package/dist/MessageActions/index.js +6 -5
- package/dist/Modal/index.js +7 -6
- package/dist/MoneyField/index.js +5 -4
- package/dist/NewItemsNotice/index.js +3 -2
- package/dist/NumberField/index.js +5 -4
- package/dist/OrgTable/index.js +9 -8
- package/dist/PrincipalPicker/index.js +6 -5
- package/dist/ProposalCard/index.js +8 -7
- package/dist/ReactionBar/index.js +6 -5
- package/dist/Reorder/index.js +3 -2
- package/dist/RichEditor/index.js +1 -1
- package/dist/ScopeList/index.js +6 -5
- package/dist/SelectionBar/index.js +3 -2
- package/dist/SendKeys/index.js +3 -2
- package/dist/SettingForm/index.js +5 -4
- package/dist/ShareDialog/index.js +8 -7
- package/dist/SheetColumnEditor/index.js +8 -6
- package/dist/SheetGrid/index.js +5 -4
- package/dist/SlideFilmstrip/index.js +6 -4
- package/dist/Switcher/index.js +8 -7
- package/dist/TagGroup/index.js +3 -2
- package/dist/TagsInput/index.js +3 -2
- package/dist/TimeRangePicker/index.js +8 -7
- package/dist/TimeWindowPicker/index.js +5 -4
- package/dist/TreeCanvas/index.js +4 -3
- package/dist/TreeGrid/index.js +8 -7
- package/dist/ValueField/index.js +6 -5
- package/dist/VersionCompare/index.js +1 -1
- package/dist/{chunk-VBBLHS2Y.js → chunk-25LIX6UI.js} +0 -1
- package/dist/{chunk-XKC7EJGR.js → chunk-2DFB7NHX.js} +39 -13
- package/dist/{chunk-YHLLBQJA.js → chunk-2EALNWKD.js} +1 -1
- package/dist/{chunk-TDRWUWGV.js → chunk-2SSTJDRV.js} +1 -1
- package/dist/{chunk-VNEUVMUR.js → chunk-2ZNOHIT4.js} +2 -2
- package/dist/{chunk-EK5NJV6K.js → chunk-4P24HLY3.js} +2 -2
- package/dist/{chunk-ERNIXJMN.js → chunk-4RQTYNJB.js} +1 -1
- package/dist/{chunk-BE5NESX4.js → chunk-4X33B7RC.js} +1 -1
- package/dist/{chunk-NIII72XP.js → chunk-5AOJFG2K.js} +1 -1
- package/dist/{chunk-ZLHVKPAQ.js → chunk-5PCC5XTZ.js} +1 -1
- package/dist/{chunk-IAOROOL6.js → chunk-5YYAI32W.js} +4 -4
- package/dist/{chunk-CUQN6WSD.js → chunk-6AU73W3Y.js} +2 -2
- package/dist/{chunk-S6ES6MMW.js → chunk-6EJS374X.js} +2 -2
- package/dist/{chunk-C4BENQB3.js → chunk-A24SEWF7.js} +2 -2
- package/dist/{chunk-NHQ3CXFN.js → chunk-ANCFMQBV.js} +1 -1
- package/dist/{chunk-OAWECVU2.js → chunk-B4TAERAM.js} +1 -1
- package/dist/{chunk-TEXK4RK6.js → chunk-BGVJBX7E.js} +1 -1
- package/dist/chunk-CB6MUWCA.js +206 -0
- package/dist/{chunk-R72QM6WV.js → chunk-CC4TFCOT.js} +4 -1
- package/dist/chunk-CI4HUVNI.js +197 -0
- package/dist/{chunk-SETK4FN5.js → chunk-CVNUXLMI.js} +1 -1
- package/dist/{chunk-FOJ3TVKJ.js → chunk-DON7AM43.js} +1 -1
- package/dist/{chunk-DDVUPYJW.js → chunk-EDHRJQZT.js} +1 -1
- package/dist/{chunk-HWJVQFXQ.js → chunk-EJDWUXFJ.js} +3 -3
- package/dist/{chunk-H77NQVS7.js → chunk-ETWGKTMC.js} +1 -1
- package/dist/{chunk-237WBIAN.js → chunk-EZO5MYII.js} +1 -1
- package/dist/{chunk-SQPT4UZ4.js → chunk-GEFO45DZ.js} +1 -1
- package/dist/{chunk-2SGJAD7O.js → chunk-HC5Y4ZVY.js} +1 -1
- package/dist/{chunk-WLYAGMZA.js → chunk-HI3AFP34.js} +1 -1
- package/dist/{chunk-WASYD3IL.js → chunk-I6D4QYZL.js} +4 -2
- package/dist/{chunk-HUZ27VZ7.js → chunk-IFL6DM5K.js} +1 -1
- package/dist/chunk-JNTOZ5LE.js +49 -0
- package/dist/{chunk-YUVQUJND.js → chunk-K657TVMA.js} +1 -1
- package/dist/{chunk-NCQC5Y4E.js → chunk-LIOO7OMN.js} +1 -1
- package/dist/{chunk-BD2HPIZ2.js → chunk-LN7IMSCU.js} +1 -1
- package/dist/{chunk-R5UTN5QB.js → chunk-LNPN3DV2.js} +2 -2
- package/dist/{chunk-KIPEB2UV.js → chunk-MKOWEHDH.js} +1 -1
- package/dist/{chunk-U2TENSNB.js → chunk-MZAMX65M.js} +1 -1
- package/dist/chunk-MZP5A3NQ.js +1 -0
- package/dist/{chunk-2OYEVTF4.js → chunk-N2AIHIYX.js} +2 -2
- package/dist/{chunk-MSKRVYGH.js → chunk-N72QMEEA.js} +1 -1
- package/dist/{chunk-Y5GBXHA6.js → chunk-NB5HDW7O.js} +2 -2
- package/dist/{chunk-ZR276S44.js → chunk-NLYURJUF.js} +2 -2
- package/dist/chunk-NQ7LG6BU.js +1 -0
- package/dist/{chunk-J6QNUNZD.js → chunk-ORX3PYX3.js} +1 -1
- package/dist/{chunk-QVSG3XSW.js → chunk-QGZPXZHE.js} +2 -2
- package/dist/{chunk-2FWNVZSX.js → chunk-QJEC2XZH.js} +2 -2
- package/dist/{chunk-4RVDOEJR.js → chunk-RTLBWYVV.js} +2 -2
- package/dist/{chunk-FTOKCN4I.js → chunk-SFBIOHM3.js} +2 -2
- package/dist/{chunk-H7V4QAOV.js → chunk-SXCUNON2.js} +1 -1
- package/dist/{chunk-ZDENBTBY.js → chunk-SXUKSA6U.js} +1 -1
- package/dist/{chunk-G5UBUODG.js → chunk-T2DGBIFD.js} +1 -1
- package/dist/{chunk-LR56IYSL.js → chunk-TJFJMMCR.js} +2 -2
- package/dist/{chunk-MFJYXWN5.js → chunk-UN5BTYDI.js} +5 -5
- package/dist/{chunk-ZQTEBONP.js → chunk-VNCKUYYT.js} +1 -1
- package/dist/{chunk-MFRXKQAF.js → chunk-XHQ6BRGS.js} +1 -1
- package/dist/{chunk-NJBKJF3Q.js → chunk-XKFZBWXA.js} +2 -2
- package/dist/{chunk-U7AHXPYA.js → chunk-XLB7QIXK.js} +3 -3
- package/dist/{chunk-IF5RMDDV.js → chunk-XLOBTFLR.js} +3 -3
- package/dist/{chunk-RYS3SN7J.js → chunk-XTT2XWVQ.js} +1 -1
- package/dist/{chunk-ZCKC7ENV.js → chunk-Y22OHIVL.js} +2 -2
- package/dist/{chunk-2DESFB7K.js → chunk-YER6BEBM.js} +1 -1
- package/dist/{chunk-M4XBRBZL.js → chunk-YNPIGUJF.js} +1 -1
- package/dist/{chunk-KQTWO46B.js → chunk-YOGPQDXA.js} +1 -1
- package/dist/{chunk-4TLKCRE4.js → chunk-YW3IH3EU.js} +1 -1
- package/dist/{chunk-EPVQ4OZ3.js → chunk-YXRMGI4B.js} +1 -1
- package/dist/{chunk-QR4LRVWK.js → chunk-ZH45BDTS.js} +1 -1
- package/dist/generated/index.d.ts +1 -0
- package/dist/generated/index.js +96 -91
- package/dist/index.js +96 -91
- package/dist/session-XDRRVFVE.js +789 -0
- package/dist/styles.css +148 -3
- package/dist/webSpeech-CJNDQU3D.js +165 -0
- package/package.json +3 -3
- /package/dist/{chunk-WGMKERCR.js → chunk-AZQBGKPR.js} +0 -0
- /package/dist/{chunk-LE7SVMCB.js → chunk-JJEGPEV7.js} +0 -0
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
import { dictationLabels } from './chunk-JNTOZ5LE.js';
|
|
2
|
+
import { notify, DICTATION_SHORTCUT, chordMatches, browserBlock } from './chunk-CI4HUVNI.js';
|
|
3
|
+
import { isApplePlatform } from './chunk-25LIX6UI.js';
|
|
4
|
+
import './chunk-43N4EHFR.js';
|
|
5
|
+
import './chunk-SK4BIFTG.js';
|
|
6
|
+
import { prefersReducedMotion } from './chunk-COS6LJ4K.js';
|
|
7
|
+
import './chunk-YVMIT2OW.js';
|
|
8
|
+
import { Spinner } from './chunk-XSPCITPN.js';
|
|
9
|
+
import { copyTextStyles } from './chunk-AKLZJTOJ.js';
|
|
10
|
+
import { announce } from './chunk-AZQBGKPR.js';
|
|
11
|
+
import { IconButton } from './chunk-66H4BC5Z.js';
|
|
12
|
+
import './chunk-TDFLCUBE.js';
|
|
13
|
+
import './chunk-ZF5ELYJ3.js';
|
|
14
|
+
import './chunk-HTS5RJ7S.js';
|
|
15
|
+
import './chunk-L72URIHR.js';
|
|
16
|
+
import './chunk-NCM4VYRF.js';
|
|
17
|
+
import './chunk-EDPMHSLZ.js';
|
|
18
|
+
import './chunk-4ITETIGZ.js';
|
|
19
|
+
import './chunk-RRRK2KB6.js';
|
|
20
|
+
import './chunk-ODEQTPFM.js';
|
|
21
|
+
import { useRef, useSyncExternalStore, useLayoutEffect, useEffect } from 'react';
|
|
22
|
+
import { XGlyph, CheckGlyph, MicGlyph } from '@crewlethq/icons/glyphs';
|
|
23
|
+
export { MicOffGlyph } from '@crewlethq/icons/glyphs';
|
|
24
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
25
|
+
|
|
26
|
+
// src/Dictation/microphone.ts
|
|
27
|
+
var QUERY = { name: "microphone" };
|
|
28
|
+
function captureOf(stream) {
|
|
29
|
+
const context = new AudioContext();
|
|
30
|
+
const analyser = context.createAnalyser();
|
|
31
|
+
analyser.fftSize = 512;
|
|
32
|
+
context.createMediaStreamSource(stream).connect(analyser);
|
|
33
|
+
void context.resume().catch(() => void 0);
|
|
34
|
+
const data = new Float32Array(analyser.fftSize);
|
|
35
|
+
const track = stream.getAudioTracks()[0];
|
|
36
|
+
return {
|
|
37
|
+
stream,
|
|
38
|
+
level() {
|
|
39
|
+
analyser.getFloatTimeDomainData(data);
|
|
40
|
+
let sum = 0;
|
|
41
|
+
for (const sample of data) sum += sample * sample;
|
|
42
|
+
return Math.min(1, Math.sqrt(sum / data.length) * 5);
|
|
43
|
+
},
|
|
44
|
+
onEnded(listener) {
|
|
45
|
+
track?.addEventListener("ended", listener, { once: true });
|
|
46
|
+
},
|
|
47
|
+
stop() {
|
|
48
|
+
for (const each of stream.getTracks()) each.stop();
|
|
49
|
+
void context.close().catch(() => void 0);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function browserMicrophone() {
|
|
54
|
+
return {
|
|
55
|
+
check: browserBlock,
|
|
56
|
+
async permission() {
|
|
57
|
+
try {
|
|
58
|
+
return (await navigator.permissions.query(QUERY)).state;
|
|
59
|
+
} catch {
|
|
60
|
+
return "unknown";
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
onPermissionChange(listener) {
|
|
64
|
+
let status = null;
|
|
65
|
+
let gone = false;
|
|
66
|
+
navigator.permissions?.query(QUERY).then((answer) => {
|
|
67
|
+
if (gone) return;
|
|
68
|
+
status = answer;
|
|
69
|
+
answer.onchange = () => listener(answer.state);
|
|
70
|
+
}).catch(() => void 0);
|
|
71
|
+
return () => {
|
|
72
|
+
gone = true;
|
|
73
|
+
if (status) status.onchange = null;
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
async devices() {
|
|
77
|
+
const all = await navigator.mediaDevices.enumerateDevices();
|
|
78
|
+
return all.filter((d) => d.kind === "audioinput").map((d) => ({ deviceId: d.deviceId, label: d.label }));
|
|
79
|
+
},
|
|
80
|
+
onDeviceChange(listener) {
|
|
81
|
+
navigator.mediaDevices.addEventListener("devicechange", listener);
|
|
82
|
+
return () => navigator.mediaDevices.removeEventListener("devicechange", listener);
|
|
83
|
+
},
|
|
84
|
+
async open(deviceId) {
|
|
85
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
86
|
+
audio: deviceId ? { deviceId: { exact: deviceId } } : true
|
|
87
|
+
});
|
|
88
|
+
return captureOf(stream);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/Dictation/machine.ts
|
|
94
|
+
var FLUSH_MS = 1500;
|
|
95
|
+
var SILENT_LEVEL = 0.08;
|
|
96
|
+
var GATE_MS = 250;
|
|
97
|
+
var NOTE_MS = 8e3;
|
|
98
|
+
var STORE_KEY = "crewlet:dictation:device";
|
|
99
|
+
var session = null;
|
|
100
|
+
var notes = /* @__PURE__ */ new Map();
|
|
101
|
+
var states = /* @__PURE__ */ new WeakMap();
|
|
102
|
+
var browser = null;
|
|
103
|
+
var words = 0;
|
|
104
|
+
var wordListeners = /* @__PURE__ */ new Set();
|
|
105
|
+
function wordsChanged() {
|
|
106
|
+
words += 1;
|
|
107
|
+
for (const listener of [...wordListeners]) listener();
|
|
108
|
+
}
|
|
109
|
+
function subscribeWords(listener) {
|
|
110
|
+
wordListeners.add(listener);
|
|
111
|
+
return () => wordListeners.delete(listener);
|
|
112
|
+
}
|
|
113
|
+
function wordsVersion() {
|
|
114
|
+
return words;
|
|
115
|
+
}
|
|
116
|
+
function activeSession() {
|
|
117
|
+
return session;
|
|
118
|
+
}
|
|
119
|
+
function resumable(reason) {
|
|
120
|
+
return reason === "paused" || reason === "silence";
|
|
121
|
+
}
|
|
122
|
+
function remember(id) {
|
|
123
|
+
try {
|
|
124
|
+
if (id === void 0) localStorage.removeItem(STORE_KEY);
|
|
125
|
+
else localStorage.setItem(STORE_KEY, id);
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function recall() {
|
|
130
|
+
try {
|
|
131
|
+
return localStorage.getItem(STORE_KEY) ?? void 0;
|
|
132
|
+
} catch {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function micOf(source) {
|
|
137
|
+
return source.microphone ?? (browser ??= browserMicrophone());
|
|
138
|
+
}
|
|
139
|
+
function micState(source) {
|
|
140
|
+
const mic = micOf(source);
|
|
141
|
+
let state = states.get(mic);
|
|
142
|
+
if (!state) {
|
|
143
|
+
state = { mic, permission: "unknown", devices: null, chosen: recall(), gone: false, picks: false };
|
|
144
|
+
states.set(mic, state);
|
|
145
|
+
void probe(state);
|
|
146
|
+
}
|
|
147
|
+
return state;
|
|
148
|
+
}
|
|
149
|
+
async function probe(m) {
|
|
150
|
+
if (m.mic.check()) return;
|
|
151
|
+
m.permission = await m.mic.permission().catch(() => "unknown");
|
|
152
|
+
m.mic.onPermissionChange?.((state) => {
|
|
153
|
+
m.permission = state;
|
|
154
|
+
void listDevices(m);
|
|
155
|
+
});
|
|
156
|
+
m.mic.onDeviceChange?.(() => void deviceChanged(m));
|
|
157
|
+
await listDevices(m);
|
|
158
|
+
}
|
|
159
|
+
async function listDevices(m) {
|
|
160
|
+
try {
|
|
161
|
+
m.devices = await m.mic.devices();
|
|
162
|
+
} catch {
|
|
163
|
+
m.devices = null;
|
|
164
|
+
}
|
|
165
|
+
const wanted = recall();
|
|
166
|
+
if (wanted !== void 0 && m.devices?.some((d) => d.label)) {
|
|
167
|
+
const present = m.devices.some((d) => d.deviceId === wanted);
|
|
168
|
+
m.chosen = present ? wanted : void 0;
|
|
169
|
+
m.gone = !present;
|
|
170
|
+
}
|
|
171
|
+
notify();
|
|
172
|
+
}
|
|
173
|
+
async function deviceChanged(m) {
|
|
174
|
+
await listDevices(m);
|
|
175
|
+
if (session?.mic === m && session.phase === "listening" && m.chosen === void 0) await switchTo(session, void 0);
|
|
176
|
+
}
|
|
177
|
+
function labelsOf(source) {
|
|
178
|
+
return dictationLabels(source.labels);
|
|
179
|
+
}
|
|
180
|
+
function view(owner) {
|
|
181
|
+
const source = owner.get().source;
|
|
182
|
+
const labels = labelsOf(source);
|
|
183
|
+
const m = micState(source);
|
|
184
|
+
const mine = session?.owner === owner ? session : null;
|
|
185
|
+
let held;
|
|
186
|
+
if (session && !mine) held = labels.elsewhere(session.label);
|
|
187
|
+
else if (!mine && m.permission === "denied") held = labels.denied;
|
|
188
|
+
else if (!mine && m.devices?.length === 0) held = labels.noDevice;
|
|
189
|
+
return {
|
|
190
|
+
phase: mine?.phase ?? null,
|
|
191
|
+
held,
|
|
192
|
+
off: !mine && m.permission === "denied",
|
|
193
|
+
elsewhere: session !== null && !mine,
|
|
194
|
+
note: mine ? line(mine) : notes.get(owner),
|
|
195
|
+
describe: labels.dictating,
|
|
196
|
+
resume: mine?.phase === "stopped" && resumable(mine.reason) ? labels.resume : void 0
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function line(s) {
|
|
200
|
+
if (s.phase === "preparing") return s.labels.preparing(s.progress);
|
|
201
|
+
if (s.phase === "stopped" && s.reason) return s.labels.stopped[s.reason];
|
|
202
|
+
if (s.phase === "listening" && s.quiet) return s.labels.quiet;
|
|
203
|
+
return void 0;
|
|
204
|
+
}
|
|
205
|
+
function focusActive() {
|
|
206
|
+
session?.owner.get().field.current?.focus();
|
|
207
|
+
}
|
|
208
|
+
function start(owner) {
|
|
209
|
+
if (session) {
|
|
210
|
+
if (session.owner !== owner) focusActive();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const o = owner.get();
|
|
214
|
+
const field = o.field.current;
|
|
215
|
+
const m = micState(o.source);
|
|
216
|
+
notes.delete(owner);
|
|
217
|
+
const s = {
|
|
218
|
+
owner,
|
|
219
|
+
label: o.label,
|
|
220
|
+
source: o.source,
|
|
221
|
+
labels: labelsOf(o.source),
|
|
222
|
+
mic: m,
|
|
223
|
+
value: o.value,
|
|
224
|
+
// A field never focused reports its caret at the start; the words then go at the end.
|
|
225
|
+
from: field && owner.touched ? field.selectionStart : o.value.length,
|
|
226
|
+
to: field && owner.touched ? field.selectionEnd : o.value.length,
|
|
227
|
+
finals: [],
|
|
228
|
+
partial: "",
|
|
229
|
+
phase: "pending",
|
|
230
|
+
reason: null,
|
|
231
|
+
quiet: false,
|
|
232
|
+
capture: null,
|
|
233
|
+
transport: null,
|
|
234
|
+
index: 0,
|
|
235
|
+
opening: false,
|
|
236
|
+
prepared: false,
|
|
237
|
+
progress: void 0,
|
|
238
|
+
declined: null,
|
|
239
|
+
ended: false,
|
|
240
|
+
flushing: null,
|
|
241
|
+
heard: Date.now(),
|
|
242
|
+
timer: void 0,
|
|
243
|
+
over: false
|
|
244
|
+
};
|
|
245
|
+
session = s;
|
|
246
|
+
field?.focus();
|
|
247
|
+
field?.setSelectionRange(s.from, s.from);
|
|
248
|
+
o.source.onActiveChange?.(true);
|
|
249
|
+
notify();
|
|
250
|
+
if (m.permission !== "granted") announce(s.labels.pending);
|
|
251
|
+
void open(s, false);
|
|
252
|
+
}
|
|
253
|
+
async function open(s, resuming) {
|
|
254
|
+
let capture;
|
|
255
|
+
try {
|
|
256
|
+
capture = await s.mic.mic.open(s.mic.chosen);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (session !== s || s.over) return;
|
|
259
|
+
const name = error?.name;
|
|
260
|
+
if ((name === "OverconstrainedError" || name === "NotFoundError") && s.mic.chosen !== void 0) {
|
|
261
|
+
s.mic.chosen = void 0;
|
|
262
|
+
s.mic.gone = true;
|
|
263
|
+
return open(s, resuming);
|
|
264
|
+
}
|
|
265
|
+
end(s);
|
|
266
|
+
restore(s);
|
|
267
|
+
if (name === "NotAllowedError" || name === "SecurityError") {
|
|
268
|
+
s.mic.permission = "denied";
|
|
269
|
+
announce(s.labels.denied);
|
|
270
|
+
} else if (name === "NotFoundError" || name === "OverconstrainedError") {
|
|
271
|
+
s.mic.devices = [];
|
|
272
|
+
announce(s.labels.noDevice);
|
|
273
|
+
} else {
|
|
274
|
+
note(s.owner, s.labels.busy);
|
|
275
|
+
}
|
|
276
|
+
notify();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (session !== s || s.over) {
|
|
280
|
+
capture.stop();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
s.capture = capture;
|
|
284
|
+
s.mic.permission = "granted";
|
|
285
|
+
capture.onEnded(() => {
|
|
286
|
+
if (s.capture === capture) stop(s, "unplugged");
|
|
287
|
+
});
|
|
288
|
+
s.reason = null;
|
|
289
|
+
s.ended = false;
|
|
290
|
+
s.flushing = null;
|
|
291
|
+
s.declined = null;
|
|
292
|
+
if (!s.mic.devices?.some((d) => d.label)) void listDevices(s.mic);
|
|
293
|
+
await begin(s, 0, resuming);
|
|
294
|
+
}
|
|
295
|
+
function transportsOf(source) {
|
|
296
|
+
const { transport } = source;
|
|
297
|
+
return Array.isArray(transport) ? transport : [transport];
|
|
298
|
+
}
|
|
299
|
+
async function begin(s, from, resuming) {
|
|
300
|
+
const routes = transportsOf(s.source);
|
|
301
|
+
for (let i = from; i < routes.length; i++) {
|
|
302
|
+
const t = routes[i];
|
|
303
|
+
const usable = t.available ? await Promise.resolve().then(() => t.available()).catch(() => false) : true;
|
|
304
|
+
if (session !== s || s.over) return;
|
|
305
|
+
if (!usable) {
|
|
306
|
+
s.declined ??= "unavailable";
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
Object.assign(s, { transport: t, index: i, opening: true, prepared: false, progress: void 0 });
|
|
310
|
+
try {
|
|
311
|
+
await t.start(s.mic.chosen, events(s, t, resuming), s.capture?.stream ?? null);
|
|
312
|
+
} catch {
|
|
313
|
+
if (s.transport === t && s.opening) decline(s, "unavailable", resuming);
|
|
314
|
+
else if (s.transport === t && s.phase === "listening") {
|
|
315
|
+
s.ended = true;
|
|
316
|
+
stop(s, "dropped");
|
|
317
|
+
}
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (s.transport === t && s.opening && !s.prepared) ready(s, t, resuming);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (session !== s || s.over) return;
|
|
324
|
+
const why = s.declined === "busy" ? s.labels.serviceBusy : s.labels.unavailable;
|
|
325
|
+
if (resuming || s.finals.length > 0) {
|
|
326
|
+
s.phase = "listening";
|
|
327
|
+
s.ended = true;
|
|
328
|
+
stop(s, "dropped");
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
end(s);
|
|
332
|
+
restore(s);
|
|
333
|
+
note(s.owner, why);
|
|
334
|
+
}
|
|
335
|
+
function decline(s, why, resuming) {
|
|
336
|
+
s.transport?.cancel();
|
|
337
|
+
s.transport = null;
|
|
338
|
+
s.declined = why === "busy" || s.declined === "busy" ? "busy" : "unavailable";
|
|
339
|
+
void begin(s, s.index + 1, resuming);
|
|
340
|
+
}
|
|
341
|
+
function ready(s, t, resuming) {
|
|
342
|
+
if (s.transport !== t || !s.opening || session !== s || s.over) return;
|
|
343
|
+
s.opening = false;
|
|
344
|
+
s.phase = "listening";
|
|
345
|
+
s.heard = Date.now();
|
|
346
|
+
s.mic.picks = Boolean(t.picksDevice);
|
|
347
|
+
notify();
|
|
348
|
+
if (!resuming) announce(s.labels.dictating);
|
|
349
|
+
gate(s);
|
|
350
|
+
}
|
|
351
|
+
function note(owner, text) {
|
|
352
|
+
notes.set(owner, text);
|
|
353
|
+
announce(text);
|
|
354
|
+
notify();
|
|
355
|
+
setTimeout(() => {
|
|
356
|
+
if (notes.get(owner) === text && notes.delete(owner)) notify();
|
|
357
|
+
}, NOTE_MS);
|
|
358
|
+
}
|
|
359
|
+
function events(s, t, resuming) {
|
|
360
|
+
const mine = () => session === s && !s.over && s.transport === t;
|
|
361
|
+
const heard = () => {
|
|
362
|
+
s.heard = Date.now();
|
|
363
|
+
if (s.quiet) {
|
|
364
|
+
s.quiet = false;
|
|
365
|
+
notify();
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
return {
|
|
369
|
+
preparing(progress) {
|
|
370
|
+
if (!mine() || !s.opening) return;
|
|
371
|
+
const first = s.phase !== "preparing";
|
|
372
|
+
s.prepared = true;
|
|
373
|
+
s.phase = "preparing";
|
|
374
|
+
s.progress = progress;
|
|
375
|
+
notify();
|
|
376
|
+
if (first) announce(s.labels.preparing(void 0));
|
|
377
|
+
},
|
|
378
|
+
ready() {
|
|
379
|
+
if (mine()) ready(s, t, resuming);
|
|
380
|
+
},
|
|
381
|
+
partial(text) {
|
|
382
|
+
if (!mine()) return;
|
|
383
|
+
if (s.opening) ready(s, t, resuming);
|
|
384
|
+
s.partial = text;
|
|
385
|
+
heard();
|
|
386
|
+
wordsChanged();
|
|
387
|
+
},
|
|
388
|
+
final(text) {
|
|
389
|
+
if (!mine()) return;
|
|
390
|
+
if (s.opening) ready(s, t, resuming);
|
|
391
|
+
const trimmed = text.trim();
|
|
392
|
+
if (trimmed) s.finals.push(trimmed);
|
|
393
|
+
s.partial = "";
|
|
394
|
+
heard();
|
|
395
|
+
wordsChanged();
|
|
396
|
+
},
|
|
397
|
+
error(code) {
|
|
398
|
+
if (!mine()) return;
|
|
399
|
+
const declined = code === "busy" || code === "unavailable";
|
|
400
|
+
if (s.opening && declined) return decline(s, code, resuming);
|
|
401
|
+
if (s.opening) {
|
|
402
|
+
s.opening = false;
|
|
403
|
+
s.phase = "listening";
|
|
404
|
+
}
|
|
405
|
+
if (s.phase !== "listening") return;
|
|
406
|
+
s.ended = true;
|
|
407
|
+
stop(s, declined ? "dropped" : code);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function gate(s) {
|
|
412
|
+
const { hint, stop: cut } = s.source.silence ?? { hint: 10, stop: 30 };
|
|
413
|
+
clearInterval(s.timer);
|
|
414
|
+
s.timer = setInterval(() => {
|
|
415
|
+
if (!s.capture) return;
|
|
416
|
+
const now = Date.now();
|
|
417
|
+
if (s.capture.level() > SILENT_LEVEL) s.heard = now;
|
|
418
|
+
const quiet = now - s.heard;
|
|
419
|
+
if (quiet >= cut * 1e3) stop(s, "silence");
|
|
420
|
+
else if (quiet >= hint * 1e3 !== s.quiet) {
|
|
421
|
+
s.quiet = !s.quiet;
|
|
422
|
+
notify();
|
|
423
|
+
}
|
|
424
|
+
}, GATE_MS);
|
|
425
|
+
}
|
|
426
|
+
function release(s) {
|
|
427
|
+
clearInterval(s.timer);
|
|
428
|
+
s.timer = void 0;
|
|
429
|
+
s.capture?.stop();
|
|
430
|
+
s.capture = null;
|
|
431
|
+
}
|
|
432
|
+
function settle(s) {
|
|
433
|
+
if (s.ended || !s.transport) return Promise.resolve();
|
|
434
|
+
const flushed = s.transport.flush().catch(() => void 0);
|
|
435
|
+
const timeout = new Promise((resolve) => setTimeout(resolve, FLUSH_MS));
|
|
436
|
+
return Promise.race([flushed, timeout]).then(() => {
|
|
437
|
+
s.ended = true;
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
function stop(s, reason) {
|
|
441
|
+
if (s.phase !== "listening" || session !== s) return;
|
|
442
|
+
release(s);
|
|
443
|
+
s.phase = "stopped";
|
|
444
|
+
s.reason = reason;
|
|
445
|
+
s.quiet = false;
|
|
446
|
+
s.flushing = settle(s);
|
|
447
|
+
notify();
|
|
448
|
+
announce(s.labels.stopped[reason]);
|
|
449
|
+
}
|
|
450
|
+
async function resume(s) {
|
|
451
|
+
if (s.phase !== "stopped" || !resumable(s.reason)) return;
|
|
452
|
+
s.phase = "pending";
|
|
453
|
+
notify();
|
|
454
|
+
await s.flushing;
|
|
455
|
+
if (session !== s || s.over) return;
|
|
456
|
+
void open(s, true);
|
|
457
|
+
}
|
|
458
|
+
function resumeOwner(owner) {
|
|
459
|
+
if (session?.owner === owner) void resume(session);
|
|
460
|
+
}
|
|
461
|
+
function joinWords(parts) {
|
|
462
|
+
return parts.map((part) => part.trim()).filter(Boolean).join(" ");
|
|
463
|
+
}
|
|
464
|
+
function splice(value, from, to, text) {
|
|
465
|
+
const start2 = Math.min(from, value.length);
|
|
466
|
+
const before = value.slice(0, start2);
|
|
467
|
+
const after = value.slice(Math.max(start2, Math.min(to, value.length)));
|
|
468
|
+
const words2 = text.trim();
|
|
469
|
+
const lead = before !== "" && !/\s$/.test(before) ? " " : "";
|
|
470
|
+
const tail = after !== "" && !/^[\s.,;:!?)\]}]/.test(after) ? " " : "";
|
|
471
|
+
return { value: before + lead + words2 + tail + after, caret: before.length + lead.length + words2.length };
|
|
472
|
+
}
|
|
473
|
+
async function accept(s) {
|
|
474
|
+
if (s.phase === "pending" || s.phase === "preparing" || s.phase === "accepting" || session !== s) return;
|
|
475
|
+
if (s.phase === "listening") {
|
|
476
|
+
release(s);
|
|
477
|
+
s.flushing = settle(s);
|
|
478
|
+
}
|
|
479
|
+
s.phase = "accepting";
|
|
480
|
+
notify();
|
|
481
|
+
await s.flushing;
|
|
482
|
+
if (session !== s || s.over) return;
|
|
483
|
+
commit(s, [...s.finals, s.partial], true);
|
|
484
|
+
}
|
|
485
|
+
function commit(s, parts, speak) {
|
|
486
|
+
const text = joinWords(parts);
|
|
487
|
+
end(s);
|
|
488
|
+
const o = s.owner.get();
|
|
489
|
+
if (!text) {
|
|
490
|
+
if (speak) {
|
|
491
|
+
restore(s);
|
|
492
|
+
announce(s.labels.nothing);
|
|
493
|
+
}
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const next = splice(o.value, s.from, s.to, text);
|
|
497
|
+
s.owner.caret = { value: next.value, at: next.caret };
|
|
498
|
+
o.onChange(next.value);
|
|
499
|
+
if (speak) announce(s.labels.inserted(text.split(/\s+/).length));
|
|
500
|
+
}
|
|
501
|
+
function cancel(s) {
|
|
502
|
+
if (session !== s) return;
|
|
503
|
+
if (!s.ended) s.transport?.cancel();
|
|
504
|
+
end(s);
|
|
505
|
+
restore(s);
|
|
506
|
+
announce(s.labels.cancelled);
|
|
507
|
+
}
|
|
508
|
+
function end(s) {
|
|
509
|
+
s.over = true;
|
|
510
|
+
release(s);
|
|
511
|
+
if (session === s) session = null;
|
|
512
|
+
notify();
|
|
513
|
+
s.source.onActiveChange?.(false);
|
|
514
|
+
}
|
|
515
|
+
function restore(s) {
|
|
516
|
+
const field = s.owner.get().field.current;
|
|
517
|
+
if (!field) return;
|
|
518
|
+
field.focus();
|
|
519
|
+
field.setSelectionRange(Math.min(s.from, field.value.length), Math.min(s.to, field.value.length));
|
|
520
|
+
}
|
|
521
|
+
function releaseOwner(owner) {
|
|
522
|
+
notes.delete(owner);
|
|
523
|
+
const s = session;
|
|
524
|
+
if (!s || s.owner !== owner) return;
|
|
525
|
+
if (!s.ended) s.transport?.cancel();
|
|
526
|
+
commit(s, s.finals, false);
|
|
527
|
+
}
|
|
528
|
+
function keyDown(owner, event) {
|
|
529
|
+
const s = session;
|
|
530
|
+
if (!s || s.owner !== owner || event.nativeEvent.isComposing) return false;
|
|
531
|
+
const chord = s.source.shortcut === false ? void 0 : s.source.shortcut ?? DICTATION_SHORTCUT;
|
|
532
|
+
if (event.key === "Enter") void accept(s);
|
|
533
|
+
else if (event.key === "Escape") cancel(s);
|
|
534
|
+
else if (chord && chordMatches(chord, event, isApplePlatform())) {
|
|
535
|
+
if (s.phase === "listening") stop(s, "paused");
|
|
536
|
+
else void resume(s);
|
|
537
|
+
} else return false;
|
|
538
|
+
event.preventDefault();
|
|
539
|
+
event.stopPropagation();
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
async function switchTo(s, id) {
|
|
543
|
+
let next;
|
|
544
|
+
try {
|
|
545
|
+
next = await s.mic.mic.open(id);
|
|
546
|
+
} catch {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (session !== s || s.phase !== "listening") {
|
|
550
|
+
next.stop();
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const old = s.capture;
|
|
554
|
+
s.capture = next;
|
|
555
|
+
next.onEnded(() => {
|
|
556
|
+
if (s.capture === next) stop(s, "unplugged");
|
|
557
|
+
});
|
|
558
|
+
s.transport?.switchStream?.(next.stream, id);
|
|
559
|
+
old?.stop();
|
|
560
|
+
const label = s.mic.devices?.find((d) => d.deviceId === (id ?? "default"))?.label;
|
|
561
|
+
if (label) announce(s.labels.switched(label));
|
|
562
|
+
notify();
|
|
563
|
+
}
|
|
564
|
+
async function choose(m, id) {
|
|
565
|
+
m.chosen = id;
|
|
566
|
+
m.gone = false;
|
|
567
|
+
remember(id);
|
|
568
|
+
notify();
|
|
569
|
+
if (session?.mic === m && session.phase === "listening") await switchTo(session, id);
|
|
570
|
+
}
|
|
571
|
+
async function allow(m) {
|
|
572
|
+
try {
|
|
573
|
+
(await m.mic.open(m.chosen)).stop();
|
|
574
|
+
m.permission = "granted";
|
|
575
|
+
} catch (error) {
|
|
576
|
+
if (error?.name === "NotAllowedError") m.permission = "denied";
|
|
577
|
+
}
|
|
578
|
+
await listDevices(m);
|
|
579
|
+
}
|
|
580
|
+
function menuNotes(owner) {
|
|
581
|
+
const source = owner.get().source;
|
|
582
|
+
const labels = labelsOf(source);
|
|
583
|
+
const block = micOf(source).check();
|
|
584
|
+
if (source.unavailableReason) return [source.unavailableReason];
|
|
585
|
+
if (block) return [labels[block]];
|
|
586
|
+
const m = micState(source);
|
|
587
|
+
if (m.permission === "denied") return [labels.denied, labels.deniedHelp];
|
|
588
|
+
if (m.devices?.length === 0) return [labels.noDevice];
|
|
589
|
+
return [...m.gone ? [labels.gone] : [], ...m.picks ? [labels.browserPicks] : []];
|
|
590
|
+
}
|
|
591
|
+
function meterable(owner) {
|
|
592
|
+
const source = owner.get().source;
|
|
593
|
+
const labels = labelsOf(source);
|
|
594
|
+
return micState(source).permission === "granted" && menuNotes(owner).every((n) => n === labels.gone || n === labels.browserPicks);
|
|
595
|
+
}
|
|
596
|
+
function menuItems(owner) {
|
|
597
|
+
const source = owner.get().source;
|
|
598
|
+
const labels = labelsOf(source);
|
|
599
|
+
const m = micState(source);
|
|
600
|
+
const items = [];
|
|
601
|
+
const blocked = source.unavailableReason !== void 0 || micOf(source).check() !== void 0;
|
|
602
|
+
if (!blocked && m.permission === "denied") items.push({ key: "retry", label: labels.retry, onSelect: () => void allow(m) });
|
|
603
|
+
else if (!blocked && m.devices?.length === 0) items.push({ key: "recheck", label: labels.recheck, onSelect: () => void listDevices(m) });
|
|
604
|
+
else if (!blocked) {
|
|
605
|
+
const named = m.devices?.filter((d) => d.label) ?? [];
|
|
606
|
+
if (m.permission !== "granted" || named.length === 0) {
|
|
607
|
+
items.push(
|
|
608
|
+
{ key: "default", label: labels.defaultDevice, checked: true, onSelect: () => void 0 },
|
|
609
|
+
{ key: "allow", label: labels.allowToChoose, onSelect: () => void allow(m) }
|
|
610
|
+
);
|
|
611
|
+
} else {
|
|
612
|
+
const ticked = m.chosen ?? (named.some((d) => d.deviceId === "default") ? "default" : named[0].deviceId);
|
|
613
|
+
for (const device of named) {
|
|
614
|
+
items.push({
|
|
615
|
+
key: `device:${device.deviceId}`,
|
|
616
|
+
label: device.label,
|
|
617
|
+
checked: device.deviceId === ticked,
|
|
618
|
+
onSelect: () => void choose(m, device.deviceId === "default" ? void 0 : device.deviceId)
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (source.setup) {
|
|
624
|
+
if (items.length > 0) items.push({ kind: "separator", key: "setup-rule" });
|
|
625
|
+
items.push({ key: "setup", label: source.setup.label, onSelect: source.setup.onSelect });
|
|
626
|
+
}
|
|
627
|
+
return items;
|
|
628
|
+
}
|
|
629
|
+
var BARS = 16;
|
|
630
|
+
var REST = 0.15;
|
|
631
|
+
var FRAME_MS = 60;
|
|
632
|
+
var STEADY_MS = 500;
|
|
633
|
+
function useLevel(read, draw) {
|
|
634
|
+
const latest = useRef({ read, draw });
|
|
635
|
+
latest.current = { read, draw };
|
|
636
|
+
useEffect(() => {
|
|
637
|
+
const steady = prefersReducedMotion();
|
|
638
|
+
let frame = 0;
|
|
639
|
+
let last = 0;
|
|
640
|
+
const tick = (now) => {
|
|
641
|
+
if (now - last >= (steady ? STEADY_MS : FRAME_MS)) {
|
|
642
|
+
last = now;
|
|
643
|
+
const level = latest.current.read();
|
|
644
|
+
latest.current.draw(steady ? Math.round(level * 4) / 4 : level, steady);
|
|
645
|
+
}
|
|
646
|
+
frame = requestAnimationFrame(tick);
|
|
647
|
+
};
|
|
648
|
+
frame = requestAnimationFrame(tick);
|
|
649
|
+
return () => cancelAnimationFrame(frame);
|
|
650
|
+
}, []);
|
|
651
|
+
}
|
|
652
|
+
function Wave({ owner }) {
|
|
653
|
+
const bars = useRef(null);
|
|
654
|
+
const history = useRef(Array.from({ length: BARS }, () => 0));
|
|
655
|
+
useLevel(
|
|
656
|
+
() => {
|
|
657
|
+
const s = activeSession();
|
|
658
|
+
return s?.owner === owner && s.capture ? s.capture.level() : 0;
|
|
659
|
+
},
|
|
660
|
+
(level, steady) => {
|
|
661
|
+
const row = history.current;
|
|
662
|
+
if (steady) row.fill(level);
|
|
663
|
+
else {
|
|
664
|
+
row.shift();
|
|
665
|
+
row.push(level);
|
|
666
|
+
}
|
|
667
|
+
const spans = bars.current?.children;
|
|
668
|
+
if (!spans) return;
|
|
669
|
+
for (let i = 0; i < spans.length; i++) {
|
|
670
|
+
spans[i].style.transform = `scaleY(${REST + (1 - REST) * row[i]})`;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
);
|
|
674
|
+
return /* @__PURE__ */ jsx("span", { ref: bars, className: "crewlet-dictation__wave", "aria-hidden": "true", children: history.current.map((_, i) => /* @__PURE__ */ jsx("span", { className: "crewlet-dictation__bar" }, i)) });
|
|
675
|
+
}
|
|
676
|
+
function Swap({ owner }) {
|
|
677
|
+
const s = activeSession();
|
|
678
|
+
if (!s || s.owner !== owner) return null;
|
|
679
|
+
const { labels, phase } = s;
|
|
680
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
681
|
+
/* @__PURE__ */ jsx(
|
|
682
|
+
IconButton,
|
|
683
|
+
{
|
|
684
|
+
label: labels.cancel,
|
|
685
|
+
icon: /* @__PURE__ */ jsx(XGlyph, {}),
|
|
686
|
+
variant: "secondary",
|
|
687
|
+
className: "crewlet-dictation__cancel",
|
|
688
|
+
onClick: () => cancel(s)
|
|
689
|
+
}
|
|
690
|
+
),
|
|
691
|
+
phase === "pending" || phase === "preparing" ? null : /* @__PURE__ */ jsx(
|
|
692
|
+
IconButton,
|
|
693
|
+
{
|
|
694
|
+
label: labels.accept,
|
|
695
|
+
icon: phase === "accepting" ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(CheckGlyph, {}),
|
|
696
|
+
variant: "primary",
|
|
697
|
+
"aria-busy": phase === "accepting" || void 0,
|
|
698
|
+
className: "crewlet-dictation__accept",
|
|
699
|
+
onClick: () => void accept(s)
|
|
700
|
+
}
|
|
701
|
+
)
|
|
702
|
+
] });
|
|
703
|
+
}
|
|
704
|
+
function Layer({ owner }) {
|
|
705
|
+
useSyncExternalStore(subscribeWords, wordsVersion, wordsVersion);
|
|
706
|
+
const layer = useRef(null);
|
|
707
|
+
const said = useRef(null);
|
|
708
|
+
const s = activeSession();
|
|
709
|
+
const mine = s?.owner === owner ? s : null;
|
|
710
|
+
const field = owner.get().field.current;
|
|
711
|
+
const value = owner.get().value;
|
|
712
|
+
const provisional = mine ? joinWords([...mine.finals, mine.partial]) : "";
|
|
713
|
+
const from = Math.min(mine?.from ?? 0, value.length);
|
|
714
|
+
const to = Math.min(Math.max(from, mine?.to ?? 0), value.length);
|
|
715
|
+
const shown = provisional ? splice(value, from, to, provisional) : null;
|
|
716
|
+
const before = shown ? shown.value.slice(0, shown.caret - provisional.length) : value.slice(0, from);
|
|
717
|
+
const after = shown ? shown.value.slice(shown.caret) : value.slice(to);
|
|
718
|
+
useLayoutEffect(() => {
|
|
719
|
+
const el = layer.current;
|
|
720
|
+
if (!el || !field) return;
|
|
721
|
+
const place = () => {
|
|
722
|
+
const style = getComputedStyle(field);
|
|
723
|
+
copyTextStyles(style, el);
|
|
724
|
+
el.style.top = `${field.offsetTop}px`;
|
|
725
|
+
el.style.left = `${field.offsetLeft}px`;
|
|
726
|
+
el.style.height = "auto";
|
|
727
|
+
const need = Math.min(el.offsetHeight, Number.parseFloat(style.maxHeight) || Infinity);
|
|
728
|
+
if (need > field.offsetHeight) field.style.minHeight = `${need}px`;
|
|
729
|
+
el.style.height = `${field.offsetHeight}px`;
|
|
730
|
+
const end2 = said.current;
|
|
731
|
+
if (end2) el.scrollTop = Math.max(0, end2.offsetTop + end2.offsetHeight - el.clientHeight + Number.parseFloat(style.paddingBottom));
|
|
732
|
+
};
|
|
733
|
+
place();
|
|
734
|
+
const watch = typeof ResizeObserver === "function" ? new ResizeObserver(place) : null;
|
|
735
|
+
watch?.observe(field);
|
|
736
|
+
return () => watch?.disconnect();
|
|
737
|
+
});
|
|
738
|
+
useEffect(() => () => void field?.style.removeProperty("min-height"), [field]);
|
|
739
|
+
const empty = before === "" && provisional === "" && after === "";
|
|
740
|
+
return /* @__PURE__ */ jsxs("div", { ref: layer, className: "crewlet-dictation__layer", "aria-hidden": "true", children: [
|
|
741
|
+
before,
|
|
742
|
+
/* @__PURE__ */ jsx("span", { ref: said, className: "crewlet-dictation__provisional", children: empty && (mine?.phase === "listening" || mine?.phase === "pending") ? mine.labels.listening : provisional }),
|
|
743
|
+
after,
|
|
744
|
+
after.endsWith("\n") || after === "" && provisional === "" && before.endsWith("\n") ? "\u200B" : null
|
|
745
|
+
] });
|
|
746
|
+
}
|
|
747
|
+
function Meter({ m }) {
|
|
748
|
+
const fill = useRef(null);
|
|
749
|
+
const own = useRef(null);
|
|
750
|
+
useEffect(() => {
|
|
751
|
+
if (activeSession()?.capture) return;
|
|
752
|
+
let alive = true;
|
|
753
|
+
m.mic.open(m.chosen).then(
|
|
754
|
+
(capture) => {
|
|
755
|
+
if (alive) own.current = capture;
|
|
756
|
+
else capture.stop();
|
|
757
|
+
},
|
|
758
|
+
() => void 0
|
|
759
|
+
);
|
|
760
|
+
return () => {
|
|
761
|
+
alive = false;
|
|
762
|
+
own.current?.stop();
|
|
763
|
+
own.current = null;
|
|
764
|
+
};
|
|
765
|
+
}, [m, m.chosen]);
|
|
766
|
+
useLevel(
|
|
767
|
+
() => (activeSession()?.capture ?? own.current)?.level() ?? 0,
|
|
768
|
+
(level) => {
|
|
769
|
+
if (fill.current) fill.current.style.transform = `scaleX(${level})`;
|
|
770
|
+
}
|
|
771
|
+
);
|
|
772
|
+
return /* @__PURE__ */ jsxs("span", { className: "crewlet-dictation__meter", "aria-hidden": "true", children: [
|
|
773
|
+
/* @__PURE__ */ jsx(MicGlyph, { size: "sm" }),
|
|
774
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-dictation__track", children: /* @__PURE__ */ jsx("span", { ref: fill, className: "crewlet-dictation__fill" }) })
|
|
775
|
+
] });
|
|
776
|
+
}
|
|
777
|
+
function hasHeader(owner) {
|
|
778
|
+
return meterable(owner) || menuNotes(owner).length > 0;
|
|
779
|
+
}
|
|
780
|
+
function MenuHeader({ owner }) {
|
|
781
|
+
const notes2 = menuNotes(owner);
|
|
782
|
+
const meter = meterable(owner);
|
|
783
|
+
return /* @__PURE__ */ jsxs("div", { className: "crewlet-dictation__head", children: [
|
|
784
|
+
meter ? /* @__PURE__ */ jsx(Meter, { m: micState(owner.get().source) }) : null,
|
|
785
|
+
notes2.map((note2) => /* @__PURE__ */ jsx("p", { className: "crewlet-dictation__help", children: note2 }, note2))
|
|
786
|
+
] });
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
export { Layer, MenuHeader, Swap, Wave, focusActive, hasHeader, keyDown, menuItems, releaseOwner as release, resumeOwner, start, view };
|