@epicbagel/saas-kit 1.10.0 → 1.11.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 +15 -4
- package/dist/{chunk-VBKJXNEL.js → chunk-5OF6D3GH.js} +4 -3
- package/dist/{chunk-UW67GSZ4.cjs → chunk-7QTFYEPE.cjs} +51 -25
- package/dist/{chunk-M2ZNC3TK.js → chunk-HLAHOVEI.js} +98 -2
- package/dist/chunk-KQBXAQAY.cjs +221 -0
- package/dist/{chunk-XB2D4NQK.cjs → chunk-NKWHDI4C.cjs} +4 -3
- package/dist/chunk-T3XMHWYV.js +221 -0
- package/dist/chunk-UOVA4YKW.js +153 -0
- package/dist/{chunk-O6F3LVZY.cjs → chunk-ZZ7ICQR2.cjs} +120 -24
- package/dist/hooks/use-dictation.cjs +2 -2
- package/dist/hooks/use-dictation.d.cts +5 -0
- package/dist/hooks/use-dictation.d.ts +5 -0
- package/dist/hooks/use-dictation.js +1 -1
- package/dist/primitives/agent-audio-visualizer-bar.cjs +2 -2
- package/dist/primitives/agent-audio-visualizer-bar.d.cts +1 -1
- package/dist/primitives/agent-audio-visualizer-bar.d.ts +1 -1
- package/dist/primitives/agent-audio-visualizer-bar.js +1 -1
- package/dist/primitives/alert.d.cts +1 -1
- package/dist/primitives/alert.d.ts +1 -1
- package/dist/primitives/badge.d.cts +1 -1
- package/dist/primitives/badge.d.ts +1 -1
- package/dist/primitives/bubble.d.cts +1 -1
- package/dist/primitives/bubble.d.ts +1 -1
- package/dist/primitives/button.d.cts +2 -2
- package/dist/primitives/button.d.ts +2 -2
- package/dist/primitives/chat.cjs +15 -15
- package/dist/primitives/chat.d.cts +2 -2
- package/dist/primitives/chat.d.ts +2 -2
- package/dist/primitives/chat.js +10 -10
- package/dist/primitives/dictation-provider.cjs +2 -2
- package/dist/primitives/dictation-provider.js +1 -1
- package/dist/primitives/voice-dictation-button.cjs +5 -3
- package/dist/primitives/voice-dictation-button.d.cts +5 -9
- package/dist/primitives/voice-dictation-button.d.ts +5 -9
- package/dist/primitives/voice-dictation-button.js +4 -2
- package/dist/primitives/voice-session-controls.cjs +3 -3
- package/dist/primitives/voice-session-controls.d.cts +4 -2
- package/dist/primitives/voice-session-controls.d.ts +4 -2
- package/dist/primitives/voice-session-controls.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-HTCW6AEH.cjs +0 -223
- package/dist/chunk-KUG4ONYC.js +0 -127
- package/dist/chunk-KWV5KTOA.js +0 -223
package/dist/chunk-HTCW6AEH.cjs
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkJDEXZGIYcjs = require('./chunk-JDEXZGIY.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkKWLSBTB2cjs = require('./chunk-KWLSBTB2.cjs');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _chunkO6F3LVZYcjs = require('./chunk-O6F3LVZY.cjs');
|
|
11
|
-
|
|
12
|
-
// src/primitives/voice-dictation-button.tsx
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _react = require('react');
|
|
19
|
-
var _reactdialog = require('@radix-ui/react-dialog'); var DialogPrimitive = _interopRequireWildcard(_reactdialog);
|
|
20
|
-
var _lucidereact = require('lucide-react');
|
|
21
|
-
var _jsxruntime = require('react/jsx-runtime');
|
|
22
|
-
function VoiceDictationButton({
|
|
23
|
-
onCommit,
|
|
24
|
-
onCancel,
|
|
25
|
-
title = "Dictate your message",
|
|
26
|
-
caption = "listening",
|
|
27
|
-
lang = "en-US",
|
|
28
|
-
continuous = true,
|
|
29
|
-
className,
|
|
30
|
-
size = "sm",
|
|
31
|
-
showLabel = false,
|
|
32
|
-
children,
|
|
33
|
-
disabled = false,
|
|
34
|
-
visibility = "visible",
|
|
35
|
-
shrink = true
|
|
36
|
-
}) {
|
|
37
|
-
const [open, setOpen] = _react.useState.call(void 0, false);
|
|
38
|
-
const capture = _chunkO6F3LVZYcjs.useDictation.call(void 0, { lang, continuous });
|
|
39
|
-
const { transcript, interimTranscript: interim, supported, error } = capture;
|
|
40
|
-
const generation = _react.useRef.call(void 0, 0);
|
|
41
|
-
const finishing = _react.useRef.call(void 0, false);
|
|
42
|
-
const busy = capture.state === "requesting" || capture.state === "transcribing";
|
|
43
|
-
const openOverlay = _react.useCallback.call(void 0, () => {
|
|
44
|
-
generation.current++;
|
|
45
|
-
finishing.current = false;
|
|
46
|
-
setOpen(true);
|
|
47
|
-
void capture.start();
|
|
48
|
-
}, [capture.start]);
|
|
49
|
-
const closeOverlay = _react.useCallback.call(void 0, () => {
|
|
50
|
-
generation.current++;
|
|
51
|
-
finishing.current = false;
|
|
52
|
-
capture.cancel();
|
|
53
|
-
setOpen(false);
|
|
54
|
-
}, [capture.cancel]);
|
|
55
|
-
const handleDone = _react.useCallback.call(void 0, async () => {
|
|
56
|
-
if (finishing.current || busy) return;
|
|
57
|
-
if (capture.state === "error" && !capture.canRetry) {
|
|
58
|
-
void capture.start();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
finishing.current = true;
|
|
62
|
-
const started = generation.current;
|
|
63
|
-
const final = await (capture.canRetry ? capture.retry() : capture.stop());
|
|
64
|
-
if (started !== generation.current) return;
|
|
65
|
-
finishing.current = false;
|
|
66
|
-
if (final === null) return;
|
|
67
|
-
closeOverlay();
|
|
68
|
-
if (final) onCommit(final);
|
|
69
|
-
else _optionalChain([onCancel, 'optionalCall', _ => _()]);
|
|
70
|
-
}, [busy, capture.canRetry, capture.retry, capture.start, capture.state, capture.stop, onCommit, onCancel, closeOverlay]);
|
|
71
|
-
const handleCancel = _react.useCallback.call(void 0, () => {
|
|
72
|
-
closeOverlay();
|
|
73
|
-
_optionalChain([onCancel, 'optionalCall', _2 => _2()]);
|
|
74
|
-
}, [closeOverlay, onCancel]);
|
|
75
|
-
_react.useEffect.call(void 0, () => {
|
|
76
|
-
if (open && capture.state === "idle") handleCancel();
|
|
77
|
-
}, [capture.state, handleCancel, open]);
|
|
78
|
-
_react.useEffect.call(void 0, () => {
|
|
79
|
-
if (!open) return;
|
|
80
|
-
const onKey = (e) => {
|
|
81
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
82
|
-
e.preventDefault();
|
|
83
|
-
void handleDone();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
document.addEventListener("keydown", onKey);
|
|
87
|
-
return () => document.removeEventListener("keydown", onKey);
|
|
88
|
-
}, [open, handleDone]);
|
|
89
|
-
_react.useEffect.call(void 0, () => {
|
|
90
|
-
return () => {
|
|
91
|
-
generation.current++;
|
|
92
|
-
};
|
|
93
|
-
}, []);
|
|
94
|
-
if (!supported) return null;
|
|
95
|
-
const displayTranscript = `${transcript}${interim ? (transcript ? " " : "") + interim : ""}`;
|
|
96
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
97
|
-
children ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
98
|
-
"button",
|
|
99
|
-
{
|
|
100
|
-
type: "button",
|
|
101
|
-
onClick: openOverlay,
|
|
102
|
-
disabled,
|
|
103
|
-
"aria-label": "Start dictation",
|
|
104
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0, visibility === "hidden" && "hidden", className),
|
|
105
|
-
children
|
|
106
|
-
}
|
|
107
|
-
) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
108
|
-
_chunkJDEXZGIYcjs.Button,
|
|
109
|
-
{
|
|
110
|
-
type: "button",
|
|
111
|
-
onClick: openOverlay,
|
|
112
|
-
disabled,
|
|
113
|
-
variant: "outline",
|
|
114
|
-
size,
|
|
115
|
-
"aria-label": "Start dictation",
|
|
116
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0, "transition-colors", visibility === "hidden" && "hidden", !shrink && "shrink-0", className),
|
|
117
|
-
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center justify-center gap-2", children: [
|
|
118
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Mic, { className: "h-4 w-4" }),
|
|
119
|
-
showLabel && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Speak" })
|
|
120
|
-
] })
|
|
121
|
-
}
|
|
122
|
-
),
|
|
123
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
124
|
-
DialogPrimitive.Root,
|
|
125
|
-
{
|
|
126
|
-
open,
|
|
127
|
-
onOpenChange: (next) => {
|
|
128
|
-
if (!next) handleCancel();
|
|
129
|
-
},
|
|
130
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DialogPrimitive.Portal, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
131
|
-
DialogPrimitive.Content,
|
|
132
|
-
{
|
|
133
|
-
"aria-label": "Voice dictation",
|
|
134
|
-
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
135
|
-
onMouseDown: (e) => {
|
|
136
|
-
if (e.target === e.currentTarget) handleCancel();
|
|
137
|
-
},
|
|
138
|
-
className: "fixed inset-0 z-[200] flex flex-col bg-background outline-hidden md:items-center md:justify-center md:bg-black/40 md:backdrop-blur-sm",
|
|
139
|
-
children: [
|
|
140
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, DialogPrimitive.Title, { className: "sr-only", children: "Voice dictation" }),
|
|
141
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, DialogPrimitive.Description, { className: "sr-only", children: "Record your message, then choose Done to add the text. Cancel discards the recording." }),
|
|
142
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 md:flex-initial w-full md:max-w-lg md:rounded-xl bg-background flex flex-col md:max-h-[80vh] md:shadow-2xl md:border md:border-border", children: [
|
|
143
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center justify-between px-4 py-3 border-b border-border md:rounded-t-xl", children: [
|
|
144
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { role: "status", className: "font-mono text-xs uppercase tracking-wider text-muted-foreground", children: capture.state === "transcribing" ? "transcribing" : capture.state === "requesting" ? "microphone" : caption }),
|
|
145
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
146
|
-
"button",
|
|
147
|
-
{
|
|
148
|
-
type: "button",
|
|
149
|
-
onClick: handleCancel,
|
|
150
|
-
"aria-label": "Cancel",
|
|
151
|
-
className: "p-1 -m-1 rounded-sm hover:bg-muted/60 transition-colors",
|
|
152
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.X, { className: "h-4 w-4" })
|
|
153
|
-
}
|
|
154
|
-
)
|
|
155
|
-
] }),
|
|
156
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 flex flex-col items-center justify-center px-6 text-center", children: [
|
|
157
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative w-24 h-24 mb-10 flex items-center justify-center", children: [
|
|
158
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
159
|
-
"span",
|
|
160
|
-
{
|
|
161
|
-
"aria-hidden": true,
|
|
162
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0,
|
|
163
|
-
"absolute inset-0 rounded-full",
|
|
164
|
-
error || busy || capture.state !== "recording" ? "bg-destructive/20" : "bg-destructive/20 animate-ping"
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
),
|
|
168
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
169
|
-
"span",
|
|
170
|
-
{
|
|
171
|
-
"aria-hidden": true,
|
|
172
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0,
|
|
173
|
-
"absolute inset-2 rounded-full",
|
|
174
|
-
"bg-destructive/40"
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
),
|
|
178
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Mic, { className: "relative h-9 w-9 text-destructive-foreground" })
|
|
179
|
-
] }),
|
|
180
|
-
title && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-base font-medium text-muted-foreground mb-3", children: title }),
|
|
181
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-xl md:text-2xl leading-relaxed min-h-[5rem] max-w-xl text-foreground", children: displayTranscript ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
182
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: transcript }),
|
|
183
|
-
interim && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "text-muted-foreground", children: [
|
|
184
|
-
transcript ? " " : "",
|
|
185
|
-
interim
|
|
186
|
-
] })
|
|
187
|
-
] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground italic text-base", children: capture.state === "transcribing" ? "Converting your recording to text\u2026" : capture.state === "requesting" ? "Allow microphone access to start." : "Start speaking, then choose Done." }) }),
|
|
188
|
-
error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { role: "alert", className: "text-sm text-destructive mt-4", children: error })
|
|
189
|
-
] }),
|
|
190
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border-t border-border px-4 py-4 pb-[calc(1rem+env(safe-area-inset-bottom))] md:pb-4 md:rounded-b-xl flex flex-col items-stretch gap-2", children: [
|
|
191
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
192
|
-
_chunkJDEXZGIYcjs.Button,
|
|
193
|
-
{
|
|
194
|
-
size: "lg",
|
|
195
|
-
className: "h-12 w-full",
|
|
196
|
-
onClick: () => void handleDone(),
|
|
197
|
-
disabled: busy,
|
|
198
|
-
children: capture.state === "transcribing" ? "Transcribing\u2026" : capture.canRetry ? "Retry transcription" : error ? "Try again" : "Done"
|
|
199
|
-
}
|
|
200
|
-
),
|
|
201
|
-
capture.canRetry && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkJDEXZGIYcjs.Button, { variant: "ghost", onClick: () => void capture.start(), children: "Record again" }),
|
|
202
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
203
|
-
"button",
|
|
204
|
-
{
|
|
205
|
-
type: "button",
|
|
206
|
-
onClick: handleCancel,
|
|
207
|
-
className: "text-sm text-muted-foreground hover:text-foreground py-1",
|
|
208
|
-
children: "Cancel"
|
|
209
|
-
}
|
|
210
|
-
)
|
|
211
|
-
] })
|
|
212
|
-
] })
|
|
213
|
-
]
|
|
214
|
-
}
|
|
215
|
-
) })
|
|
216
|
-
}
|
|
217
|
-
)
|
|
218
|
-
] });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
exports.VoiceDictationButton = VoiceDictationButton;
|
package/dist/chunk-KUG4ONYC.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
AgentAudioVisualizerBar
|
|
4
|
-
} from "./chunk-VBKJXNEL.js";
|
|
5
|
-
import {
|
|
6
|
-
Button
|
|
7
|
-
} from "./chunk-W326GKML.js";
|
|
8
|
-
import {
|
|
9
|
-
cn
|
|
10
|
-
} from "./chunk-G6SRSWXB.js";
|
|
11
|
-
|
|
12
|
-
// src/primitives/voice-session-controls.tsx
|
|
13
|
-
import { useSyncExternalStore } from "react";
|
|
14
|
-
import { Mic, MicOff, PhoneOff, AudioLines } from "lucide-react";
|
|
15
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
-
var SILENCE = [];
|
|
17
|
-
var silence = () => SILENCE;
|
|
18
|
-
var noSubscription = () => () => {
|
|
19
|
-
};
|
|
20
|
-
var DEFAULT_LABELS = {
|
|
21
|
-
disconnected: "Voice chat",
|
|
22
|
-
connecting: "Connecting\u2026",
|
|
23
|
-
listening: "Listening",
|
|
24
|
-
thinking: "Thinking\u2026",
|
|
25
|
-
speaking: "Speaking",
|
|
26
|
-
reconnecting: "Reconnecting\u2026",
|
|
27
|
-
error: "Voice chat unavailable",
|
|
28
|
-
start: "Start voice chat",
|
|
29
|
-
end: "End voice chat",
|
|
30
|
-
mute: "Mute microphone",
|
|
31
|
-
unmute: "Unmute microphone",
|
|
32
|
-
muted: "Microphone muted",
|
|
33
|
-
retry: "Retry voice chat"
|
|
34
|
-
};
|
|
35
|
-
function VoiceSessionControls({
|
|
36
|
-
state,
|
|
37
|
-
onStart,
|
|
38
|
-
onEnd,
|
|
39
|
-
muted = false,
|
|
40
|
-
onMutedChange,
|
|
41
|
-
disabled = false,
|
|
42
|
-
error,
|
|
43
|
-
volumeBands,
|
|
44
|
-
audioLevels,
|
|
45
|
-
labels,
|
|
46
|
-
size = "icon",
|
|
47
|
-
className
|
|
48
|
-
}) {
|
|
49
|
-
const liveBands = useSyncExternalStore(audioLevels?.subscribe ?? noSubscription, audioLevels?.getSnapshot ?? silence, silence);
|
|
50
|
-
const copy = { ...DEFAULT_LABELS, ...labels };
|
|
51
|
-
const active = state !== "disconnected" && state !== "error";
|
|
52
|
-
const waiting = state === "connecting" || state === "reconnecting";
|
|
53
|
-
return /* @__PURE__ */ jsxs(
|
|
54
|
-
"div",
|
|
55
|
-
{
|
|
56
|
-
"data-slot": "voice-session-controls",
|
|
57
|
-
"data-state": state,
|
|
58
|
-
className: cn("flex min-w-0 items-center gap-2", active && "w-full flex-col gap-3 py-4", !active && "flex-wrap", className),
|
|
59
|
-
children: [
|
|
60
|
-
active ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
61
|
-
/* @__PURE__ */ jsx(
|
|
62
|
-
AgentAudioVisualizerBar,
|
|
63
|
-
{
|
|
64
|
-
"aria-hidden": "true",
|
|
65
|
-
size: "sm",
|
|
66
|
-
barCount: 5,
|
|
67
|
-
state: state === "reconnecting" ? "connecting" : state,
|
|
68
|
-
volumeBands: volumeBands ?? liveBands
|
|
69
|
-
}
|
|
70
|
-
),
|
|
71
|
-
/* @__PURE__ */ jsx("span", { role: "status", className: "text-sm text-muted-foreground", children: muted && state === "listening" ? copy.muted : copy[state] }),
|
|
72
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
73
|
-
/* @__PURE__ */ jsx(
|
|
74
|
-
Button,
|
|
75
|
-
{
|
|
76
|
-
type: "button",
|
|
77
|
-
variant: "ghost",
|
|
78
|
-
size: "icon",
|
|
79
|
-
className: "min-h-[44px] min-w-[44px] shrink-0",
|
|
80
|
-
"aria-label": muted ? copy.unmute : copy.mute,
|
|
81
|
-
title: muted ? copy.unmute : copy.mute,
|
|
82
|
-
"aria-pressed": muted,
|
|
83
|
-
disabled: waiting,
|
|
84
|
-
onClick: () => onMutedChange(!muted),
|
|
85
|
-
children: muted ? /* @__PURE__ */ jsx(MicOff, { "aria-hidden": "true" }) : /* @__PURE__ */ jsx(Mic, { "aria-hidden": "true" })
|
|
86
|
-
}
|
|
87
|
-
),
|
|
88
|
-
/* @__PURE__ */ jsxs(
|
|
89
|
-
Button,
|
|
90
|
-
{
|
|
91
|
-
type: "button",
|
|
92
|
-
variant: "outline",
|
|
93
|
-
shape: "pill",
|
|
94
|
-
className: "min-h-[44px] shrink-0",
|
|
95
|
-
"aria-label": copy.end,
|
|
96
|
-
title: copy.end,
|
|
97
|
-
onClick: onEnd,
|
|
98
|
-
children: [
|
|
99
|
-
/* @__PURE__ */ jsx(PhoneOff, { "aria-hidden": "true" }),
|
|
100
|
-
copy.end
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
)
|
|
104
|
-
] })
|
|
105
|
-
] }) : /* @__PURE__ */ jsx(
|
|
106
|
-
Button,
|
|
107
|
-
{
|
|
108
|
-
type: "button",
|
|
109
|
-
size: "icon",
|
|
110
|
-
shape: "circle",
|
|
111
|
-
disabled,
|
|
112
|
-
onClick: onStart,
|
|
113
|
-
"aria-label": state === "error" ? copy.retry : copy.start,
|
|
114
|
-
title: state === "error" ? copy.retry : copy.start,
|
|
115
|
-
className: cn("min-h-[44px] min-w-[44px] shrink-0 rounded-full", size === "hero" && "size-24 [&_svg]:size-7"),
|
|
116
|
-
children: /* @__PURE__ */ jsx(AudioLines, { "aria-hidden": "true" })
|
|
117
|
-
}
|
|
118
|
-
),
|
|
119
|
-
state === "error" && /* @__PURE__ */ jsx("span", { role: "alert", className: "basis-full text-xs text-destructive", children: error || copy.error })
|
|
120
|
-
]
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
VoiceSessionControls
|
|
127
|
-
};
|
package/dist/chunk-KWV5KTOA.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
Button
|
|
4
|
-
} from "./chunk-W326GKML.js";
|
|
5
|
-
import {
|
|
6
|
-
cn
|
|
7
|
-
} from "./chunk-G6SRSWXB.js";
|
|
8
|
-
import {
|
|
9
|
-
useDictation
|
|
10
|
-
} from "./chunk-M2ZNC3TK.js";
|
|
11
|
-
|
|
12
|
-
// src/primitives/voice-dictation-button.tsx
|
|
13
|
-
import {
|
|
14
|
-
useCallback,
|
|
15
|
-
useEffect,
|
|
16
|
-
useRef,
|
|
17
|
-
useState
|
|
18
|
-
} from "react";
|
|
19
|
-
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
20
|
-
import { Mic, X } from "lucide-react";
|
|
21
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
-
function VoiceDictationButton({
|
|
23
|
-
onCommit,
|
|
24
|
-
onCancel,
|
|
25
|
-
title = "Dictate your message",
|
|
26
|
-
caption = "listening",
|
|
27
|
-
lang = "en-US",
|
|
28
|
-
continuous = true,
|
|
29
|
-
className,
|
|
30
|
-
size = "sm",
|
|
31
|
-
showLabel = false,
|
|
32
|
-
children,
|
|
33
|
-
disabled = false,
|
|
34
|
-
visibility = "visible",
|
|
35
|
-
shrink = true
|
|
36
|
-
}) {
|
|
37
|
-
const [open, setOpen] = useState(false);
|
|
38
|
-
const capture = useDictation({ lang, continuous });
|
|
39
|
-
const { transcript, interimTranscript: interim, supported, error } = capture;
|
|
40
|
-
const generation = useRef(0);
|
|
41
|
-
const finishing = useRef(false);
|
|
42
|
-
const busy = capture.state === "requesting" || capture.state === "transcribing";
|
|
43
|
-
const openOverlay = useCallback(() => {
|
|
44
|
-
generation.current++;
|
|
45
|
-
finishing.current = false;
|
|
46
|
-
setOpen(true);
|
|
47
|
-
void capture.start();
|
|
48
|
-
}, [capture.start]);
|
|
49
|
-
const closeOverlay = useCallback(() => {
|
|
50
|
-
generation.current++;
|
|
51
|
-
finishing.current = false;
|
|
52
|
-
capture.cancel();
|
|
53
|
-
setOpen(false);
|
|
54
|
-
}, [capture.cancel]);
|
|
55
|
-
const handleDone = useCallback(async () => {
|
|
56
|
-
if (finishing.current || busy) return;
|
|
57
|
-
if (capture.state === "error" && !capture.canRetry) {
|
|
58
|
-
void capture.start();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
finishing.current = true;
|
|
62
|
-
const started = generation.current;
|
|
63
|
-
const final = await (capture.canRetry ? capture.retry() : capture.stop());
|
|
64
|
-
if (started !== generation.current) return;
|
|
65
|
-
finishing.current = false;
|
|
66
|
-
if (final === null) return;
|
|
67
|
-
closeOverlay();
|
|
68
|
-
if (final) onCommit(final);
|
|
69
|
-
else onCancel?.();
|
|
70
|
-
}, [busy, capture.canRetry, capture.retry, capture.start, capture.state, capture.stop, onCommit, onCancel, closeOverlay]);
|
|
71
|
-
const handleCancel = useCallback(() => {
|
|
72
|
-
closeOverlay();
|
|
73
|
-
onCancel?.();
|
|
74
|
-
}, [closeOverlay, onCancel]);
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
if (open && capture.state === "idle") handleCancel();
|
|
77
|
-
}, [capture.state, handleCancel, open]);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (!open) return;
|
|
80
|
-
const onKey = (e) => {
|
|
81
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
82
|
-
e.preventDefault();
|
|
83
|
-
void handleDone();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
document.addEventListener("keydown", onKey);
|
|
87
|
-
return () => document.removeEventListener("keydown", onKey);
|
|
88
|
-
}, [open, handleDone]);
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
return () => {
|
|
91
|
-
generation.current++;
|
|
92
|
-
};
|
|
93
|
-
}, []);
|
|
94
|
-
if (!supported) return null;
|
|
95
|
-
const displayTranscript = `${transcript}${interim ? (transcript ? " " : "") + interim : ""}`;
|
|
96
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
97
|
-
children ? /* @__PURE__ */ jsx(
|
|
98
|
-
"button",
|
|
99
|
-
{
|
|
100
|
-
type: "button",
|
|
101
|
-
onClick: openOverlay,
|
|
102
|
-
disabled,
|
|
103
|
-
"aria-label": "Start dictation",
|
|
104
|
-
className: cn(visibility === "hidden" && "hidden", className),
|
|
105
|
-
children
|
|
106
|
-
}
|
|
107
|
-
) : /* @__PURE__ */ jsx(
|
|
108
|
-
Button,
|
|
109
|
-
{
|
|
110
|
-
type: "button",
|
|
111
|
-
onClick: openOverlay,
|
|
112
|
-
disabled,
|
|
113
|
-
variant: "outline",
|
|
114
|
-
size,
|
|
115
|
-
"aria-label": "Start dictation",
|
|
116
|
-
className: cn("transition-colors", visibility === "hidden" && "hidden", !shrink && "shrink-0", className),
|
|
117
|
-
children: /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center gap-2", children: [
|
|
118
|
-
/* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" }),
|
|
119
|
-
showLabel && /* @__PURE__ */ jsx("span", { children: "Speak" })
|
|
120
|
-
] })
|
|
121
|
-
}
|
|
122
|
-
),
|
|
123
|
-
/* @__PURE__ */ jsx(
|
|
124
|
-
DialogPrimitive.Root,
|
|
125
|
-
{
|
|
126
|
-
open,
|
|
127
|
-
onOpenChange: (next) => {
|
|
128
|
-
if (!next) handleCancel();
|
|
129
|
-
},
|
|
130
|
-
children: /* @__PURE__ */ jsx(DialogPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
|
|
131
|
-
DialogPrimitive.Content,
|
|
132
|
-
{
|
|
133
|
-
"aria-label": "Voice dictation",
|
|
134
|
-
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
135
|
-
onMouseDown: (e) => {
|
|
136
|
-
if (e.target === e.currentTarget) handleCancel();
|
|
137
|
-
},
|
|
138
|
-
className: "fixed inset-0 z-[200] flex flex-col bg-background outline-hidden md:items-center md:justify-center md:bg-black/40 md:backdrop-blur-sm",
|
|
139
|
-
children: [
|
|
140
|
-
/* @__PURE__ */ jsx(DialogPrimitive.Title, { className: "sr-only", children: "Voice dictation" }),
|
|
141
|
-
/* @__PURE__ */ jsx(DialogPrimitive.Description, { className: "sr-only", children: "Record your message, then choose Done to add the text. Cancel discards the recording." }),
|
|
142
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 md:flex-initial w-full md:max-w-lg md:rounded-xl bg-background flex flex-col md:max-h-[80vh] md:shadow-2xl md:border md:border-border", children: [
|
|
143
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3 border-b border-border md:rounded-t-xl", children: [
|
|
144
|
-
/* @__PURE__ */ jsx("span", { role: "status", className: "font-mono text-xs uppercase tracking-wider text-muted-foreground", children: capture.state === "transcribing" ? "transcribing" : capture.state === "requesting" ? "microphone" : caption }),
|
|
145
|
-
/* @__PURE__ */ jsx(
|
|
146
|
-
"button",
|
|
147
|
-
{
|
|
148
|
-
type: "button",
|
|
149
|
-
onClick: handleCancel,
|
|
150
|
-
"aria-label": "Cancel",
|
|
151
|
-
className: "p-1 -m-1 rounded-sm hover:bg-muted/60 transition-colors",
|
|
152
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
153
|
-
}
|
|
154
|
-
)
|
|
155
|
-
] }),
|
|
156
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center px-6 text-center", children: [
|
|
157
|
-
/* @__PURE__ */ jsxs("div", { className: "relative w-24 h-24 mb-10 flex items-center justify-center", children: [
|
|
158
|
-
/* @__PURE__ */ jsx(
|
|
159
|
-
"span",
|
|
160
|
-
{
|
|
161
|
-
"aria-hidden": true,
|
|
162
|
-
className: cn(
|
|
163
|
-
"absolute inset-0 rounded-full",
|
|
164
|
-
error || busy || capture.state !== "recording" ? "bg-destructive/20" : "bg-destructive/20 animate-ping"
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
),
|
|
168
|
-
/* @__PURE__ */ jsx(
|
|
169
|
-
"span",
|
|
170
|
-
{
|
|
171
|
-
"aria-hidden": true,
|
|
172
|
-
className: cn(
|
|
173
|
-
"absolute inset-2 rounded-full",
|
|
174
|
-
"bg-destructive/40"
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
),
|
|
178
|
-
/* @__PURE__ */ jsx(Mic, { className: "relative h-9 w-9 text-destructive-foreground" })
|
|
179
|
-
] }),
|
|
180
|
-
title && /* @__PURE__ */ jsx("div", { className: "text-base font-medium text-muted-foreground mb-3", children: title }),
|
|
181
|
-
/* @__PURE__ */ jsx("p", { className: "text-xl md:text-2xl leading-relaxed min-h-[5rem] max-w-xl text-foreground", children: displayTranscript ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
182
|
-
/* @__PURE__ */ jsx("span", { children: transcript }),
|
|
183
|
-
interim && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
184
|
-
transcript ? " " : "",
|
|
185
|
-
interim
|
|
186
|
-
] })
|
|
187
|
-
] }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground italic text-base", children: capture.state === "transcribing" ? "Converting your recording to text\u2026" : capture.state === "requesting" ? "Allow microphone access to start." : "Start speaking, then choose Done." }) }),
|
|
188
|
-
error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-sm text-destructive mt-4", children: error })
|
|
189
|
-
] }),
|
|
190
|
-
/* @__PURE__ */ jsxs("div", { className: "border-t border-border px-4 py-4 pb-[calc(1rem+env(safe-area-inset-bottom))] md:pb-4 md:rounded-b-xl flex flex-col items-stretch gap-2", children: [
|
|
191
|
-
/* @__PURE__ */ jsx(
|
|
192
|
-
Button,
|
|
193
|
-
{
|
|
194
|
-
size: "lg",
|
|
195
|
-
className: "h-12 w-full",
|
|
196
|
-
onClick: () => void handleDone(),
|
|
197
|
-
disabled: busy,
|
|
198
|
-
children: capture.state === "transcribing" ? "Transcribing\u2026" : capture.canRetry ? "Retry transcription" : error ? "Try again" : "Done"
|
|
199
|
-
}
|
|
200
|
-
),
|
|
201
|
-
capture.canRetry && /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => void capture.start(), children: "Record again" }),
|
|
202
|
-
/* @__PURE__ */ jsx(
|
|
203
|
-
"button",
|
|
204
|
-
{
|
|
205
|
-
type: "button",
|
|
206
|
-
onClick: handleCancel,
|
|
207
|
-
className: "text-sm text-muted-foreground hover:text-foreground py-1",
|
|
208
|
-
children: "Cancel"
|
|
209
|
-
}
|
|
210
|
-
)
|
|
211
|
-
] })
|
|
212
|
-
] })
|
|
213
|
-
]
|
|
214
|
-
}
|
|
215
|
-
) })
|
|
216
|
-
}
|
|
217
|
-
)
|
|
218
|
-
] });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export {
|
|
222
|
-
VoiceDictationButton
|
|
223
|
-
};
|