diff --git a/docs/.vitepress/theme/containers/DemoPreview.vue b/docs/.vitepress/theme/containers/DemoPreview.vue index fd18c6d..8ef160c 100644 --- a/docs/.vitepress/theme/containers/DemoPreview.vue +++ b/docs/.vitepress/theme/containers/DemoPreview.vue @@ -209,6 +209,13 @@ onUnmounted(() => { // 文档预览里的过渡组件就是用来验证转场的,因此在预览范围内恢复原定时长。 @media (prefers-reduced-motion: reduce) { .tui-demo { + // 语音输入的呼吸边框是交互反馈的一部分,预览中恢复动画 + :deep(.composer.voice-active .form::after) { + animation-delay: 0s !important; + animation-duration: 1.6s !important; + animation-iteration-count: infinite !important; + } + :deep(.page-transition .push-left-enter-active) { transition-duration: 520ms, 200ms !important; } diff --git a/docs/components/ai-chat-composer.md b/docs/components/ai-chat-composer.md index 3bc5c72..2bbe2f0 100644 --- a/docs/components/ai-chat-composer.md +++ b/docs/components/ai-chat-composer.md @@ -10,18 +10,97 @@ demo-preview=../demos/ai-chat-composer/basic.vue ::: +## 语音输入 + +开启 `voice-enabled` 后,输入框为空时右侧发送按钮会变成语音按钮(图标 `voice-wave`,文案「语音」)。点击后输入区切换为「按住说话」,右侧按钮变为键盘按钮(图标 `keyboard-1`,文案「输入」);点击键盘按钮回到文本输入。组件只负责手势与状态展示,识别能力由业务侧接入。 + +:::preview 语音输入 || 点击语音按钮进入按住说话,识别文本实时显示在整个控件上方;松手发送,移出按住按钮后松开取消;示例接入浏览器 Web Speech API,不支持时可勾选「模拟识别」 + +demo-preview=../demos/ai-chat-composer/voice.vue + +::: + +### 交互约定 + +- 输入框有内容时右侧仍是发送按钮;只有内容为空且 `voiceState` 为 `idle` 时才显示语音入口 +- 点击语音按钮进入语音模式,输入区替换为「按住说话」按钮;按住立即触发 `voice-start`,没有长按等待 +- 按住期间整个输入卡片显示主题色呼吸边框,识别文本实时浮在整个输入卡片上方,最多两行 +- 按住时按钮文案使用 `voiceSendHint`,默认「松开发送」;指针移出按住按钮后改用 `voiceCancelHint`,默认「松开取消」 +- 松手时指针仍在按住按钮内:触发 `voice-stop`,由业务侧停止识别、取最终结果并发送 +- 松手时指针已移出按住按钮:触发 `voice-cancel`,业务侧应中断识别并丢弃本次结果 +- 指针被系统取消时同样触发 `voice-cancel` +- 语音模式右侧固定为键盘按钮(图标 `keyboard-1`,文案「输入」),识别中和按住时禁用;点击回到文本输入 +- 文本输入与按住说话共用同一输入区高度,切换模式时组件不跳动;文本域按内容换行,最少 3 行、最多 6 行,超出后在文本域内滚动 +- `voiceEnabled` 默认关闭,需要显式开启 + +`voiceState` 由业务侧驱动: + +| 状态 | 含义 | +| --- | --- | +| `idle` | 未在识别,可以切换模式或按住说话 | +| `listening` | 正在聆听,实时回写 `voiceText`,组件显示在整个控件上方 | +| `processing` | 已松手,等待最终识别结果 | + +识别完成或失败后回到 `idle`。组件不会自动发送;正常松手由业务侧在 `voice-stop` 后自行处理。想换文案时用 `voiceHoldText`、`voiceSendHint`、`voiceCancelHint`、`voiceListeningText`、`voiceProcessingText`。 + +### 组件边界与兼容性 + +`AiChatComposer` 不包含 ASR,也不依赖 Web Speech API。`voice-start`、`voice-stop`、`voice-cancel` 只表达手势,录音、识别和失败降级全部由调用方决定。上面的 demo 使用 Web Speech API 只是演示适配器,可以整体换成服务端流式识别或原生桥接。 + +Web Speech API 的实际兼容性(2026-11): + +| 平台 | 情况 | +| --- | --- | +| Windows / macOS Chrome、Edge | 可用;Chromium 系通常依赖厂商在线语音服务,国内网络或离线可能报 `network` | +| macOS Safari 14.1+ | 可用(`webkitSpeechRecognition`),需要启用 Siri / 听写 | +| iOS Safari 14.5+ | 可用,需要启用 Siri;`continuous` 从 Safari 17 起才完整,之前停顿后容易提前结束 | +| Android Chrome | 可用,但 `continuous = true` 无效,停顿会结束识别;通常依赖 Google 语音服务,国内网络可能不可用 | +| Android 厂商浏览器 / 微信 / App WebView | 多数不支持或没有可用的语音服务 | +| Firefox 桌面 160+ | 有实现,但生态较新,建议实测;Firefox Android 不支持 | +| SafariViewController / iOS App 内嵌页 | Web Speech API 不可用或不可靠,改用原生桥接 | + +Web Speech API 还需要 HTTPS(localhost 除外)和麦克风授权;音频会交给浏览器厂商的服务,隐私敏感或企业内网场景不建议使用。组件在 `pointerdown` 时立即触发 `voice-start`,iOS 上应在这个事件里同步调用 `SpeechRecognition.start()`;等异步连接建立后再启动容易被用户手势策略拒绝。 + +生产环境建议把识别放到服务端流式 ASR(WebSocket)或原生语音插件。业务侧只需要按组件契约驱动状态: + +```ts +const voiceState = ref<"idle" | "listening" | "processing">("idle"); +const voiceText = ref(""); + +function onVoiceStart() { + voiceState.value = "listening"; + // 开始录音或连接 ASR;中间结果持续写入 voiceText +} + +function onVoiceStop() { + voiceState.value = "processing"; + // 停止录音,等待最终结果;拿到结果后发送 +} + +function onVoiceCancel() { + voiceState.value = "idle"; + voiceText.value = ""; + // 中断录音或识别,丢弃本次结果 +} +``` + +`voiceText` 只在按住说话区上方展示,不回写 `v-model`;语音结果由业务侧在 `voice-stop` 后取出并发送。识别不可用时退回文字输入,不要阻塞发送。 + ## 何时使用 需要单独摆放输入框时使用。多数情况下直接用 [AiChatPanel](/components/ai-chat-panel) 更省事。 ## 输入区与操作按钮 -文本域占满整行并随内容自动增高。下一行左侧是新开会话(`chat-add`)和添加附件(`file-add`),右侧根据状态显示纯文本发送或停止按钮。 +文本域占满整行并随内容自动增高。下一行左侧是新开会话(`chat-add`)和添加附件(`file-add`),右侧根据状态显示语音、键盘、发送或停止按钮。 | 状态 | 按钮 | | --- | --- | -| 空闲且未禁用 | 新开会话、添加附件、发送(`sendText`) | -| `isGenerating` 为真 | 停止(`stopText`,危险色) | +| 空闲、输入框为空且启用 `voiceEnabled` | 语音(`voice-wave`),点击进入语音模式 | +| 语音模式且未在识别 | 键盘(`keyboard-1`),点击回到文本输入 | +| 语音模式正在识别或处理 | 键盘按钮禁用 | +| 文本模式且有内容 | 发送(`sendText`) | +| `isGenerating` 为真 | 停止(`stopText`,危险色),优先于语音模式 | | 有 `lastError` 且 `canRetry` | 错误条 + 重试(`retryText`) | 生成中或 `disabled` 为真时输入框不可编辑,新开会话、添加附件和 `send` 事件不会触发。 @@ -33,12 +112,15 @@ demo-preview=../demos/ai-chat-composer/basic.vue - `retry`:点错误条上的重试 - `new-conversation`:清空输入框并请求业务侧开始一个新会话 - `add-attachment`:请求业务侧添加附件 +- `voice-start`:按住「按住说话」按钮时立即触发,可以开始录音或启动识别 +- `voice-stop`:松手且不在取消区,可以停止识别并取最终结果 +- `voice-cancel`:松手时指针已移出按住按钮,或指针被系统取消;业务侧应中断识别并丢弃本次结果 -输入框内容用 `v-model` 绑定,`maxLength` 默认 2000。 +输入框内容用 `v-model` 绑定,`maxLength` 默认 2000。语音识别结果只通过 `voiceText` 展示,不写入 `v-model`。 ## 自定义插槽 -`send`、`stop`、`error` 三个插槽可以替换对应区域的渲染,都带作用域参数(`disabled`、`onSend`、`onStop`、`error`、`canRetry`)。 +`send`、`stop`、`error` 三个插槽可以替换对应区域的渲染,都带作用域参数(`disabled`、`onSend`、`onStop`、`error`、`canRetry`)。`send` 插槽只用于文本发送;语音入口和键盘切换按钮由组件内置。 ## API diff --git a/docs/demos/ai-chat-composer/voice.vue b/docs/demos/ai-chat-composer/voice.vue new file mode 100644 index 0000000..e4eae33 --- /dev/null +++ b/docs/demos/ai-chat-composer/voice.vue @@ -0,0 +1,353 @@ + + + + + diff --git a/docs/package.json b/docs/package.json index b689610..a072c9c 100644 --- a/docs/package.json +++ b/docs/package.json @@ -10,7 +10,7 @@ "preview": "vitepress preview ." }, "dependencies": { - "tdesign-mobile-vue": "^1.17.1", + "tdesign-mobile-vue": "^1.17.2", "timi-web": "^1.0.2", "vue": "^3.5.26", "vue-router": "^4.5.0" diff --git a/docs/pnpm-lock.yaml b/docs/pnpm-lock.yaml index 53c79d0..55eaf4a 100644 --- a/docs/pnpm-lock.yaml +++ b/docs/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: tdesign-mobile-vue: - specifier: ^1.17.1 - version: 1.17.1(vue@3.5.43(typescript@5.9.3)) + specifier: ^1.17.2 + version: 1.17.2(vue@3.5.43(typescript@5.9.3)) timi-web: specifier: ^1.0.2 version: 1.0.2(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.9.3)(vue@3.5.43(typescript@5.9.3)) @@ -26,7 +26,7 @@ importers: version: 25.9.8 '@vitepress-demo-preview/plugin': specifier: ^1.4.1 - version: 1.4.1(markdown-it-container@3.0.0)(vitepress@1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(terser@5.51.2)(typescript@5.9.3))(vue@3.5.43(typescript@5.9.3)) + version: 1.4.1(markdown-it-container@3.0.0)(vitepress@1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(sortablejs@1.15.7)(terser@5.51.2)(typescript@5.9.3))(vue@3.5.43(typescript@5.9.3)) less: specifier: ^4.5.1 version: 4.9.1 @@ -41,7 +41,7 @@ importers: version: 21.1.0(@vueuse/core@12.8.2(typescript@5.9.3))(esbuild@0.21.5)(rollup@4.63.4)(vite@5.4.21(@types/node@25.9.8)(less@4.9.1)(terser@5.51.2)) vitepress: specifier: ^1.6.4 - version: 1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(terser@5.51.2)(typescript@5.9.3) + version: 1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(sortablejs@1.15.7)(terser@5.51.2)(typescript@5.9.3) vue-docgen-api: specifier: ^4.79.2 version: 4.79.2(vue@3.5.43(typescript@5.9.3)) @@ -1648,6 +1648,9 @@ packages: shiki@2.5.0: resolution: {integrity: sha512-mI//trrsaiCIPsja5CNfsyNOqgAZUb6VpJA+340toL42UpzQlXpwRV9nch69X6gaUxrr9kaOOa6e3y3uAkGFxQ==} + sortablejs@1.15.7: + resolution: {integrity: sha512-Kk8wLQPlS+yi1ZEf48a4+fzHa4yxjC30M/Sr2AnQu+f/MPwvvX9XjZ6OWejiz8crBsLwSq8GHqaxaET7u6ux0A==} + source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -1693,13 +1696,13 @@ packages: tabbable@6.5.0: resolution: {integrity: sha512-wieBHXygIm7OyQOu5hQlkk62/WyCFYGlWg7L6/ZCUZwx0o398Zkn4pVmMyfYhfMG8kGrj/Krt8eIk6UKC6VzwA==} - tdesign-icons-vue-next@0.4.11: - resolution: {integrity: sha512-lBkRUy8bdb6lQLFOOkSb1LPdl4CmZRewrc8SOUlmWkDD/DG3BTsSd/ZQ4Z767pPSlypyvxwSwcJgRv6+zjubAQ==} + tdesign-icons-vue-next@0.4.12: + resolution: {integrity: sha512-isuKOIBdOdQCCeWDiOfvdZSucXa0KC6wLBy2YvNLpRZhVxL7SjDVTulCncehzt4JFzi81LI0+dCVohw6GbfjPA==} peerDependencies: vue: ^3.0.0 - tdesign-mobile-vue@1.17.1: - resolution: {integrity: sha512-gCmhaNCc2xhSkbITHiXnE/UGs6GHLe9LTE7T26ELOENC5Cqpa+j4KYU9wz6uqFV+Ro10RkG3DFikYHnq0gNN0A==} + tdesign-mobile-vue@1.17.2: + resolution: {integrity: sha512-/MH+eNnySvMlEMwIlG0sMPOuwUuhWyOHn6HdS79ct9/+ZP+gCDzGH/usgcahZHM1l0ulY2NTlUp32opimlSZkQ==} engines: {node: '>=18.0.0'} peerDependencies: vue: ^3.2.6 @@ -2710,12 +2713,12 @@ snapshots: vite: 5.4.21(@types/node@25.9.8)(less@4.9.1)(terser@5.51.2) vue: 3.5.43(typescript@5.9.3) - '@vitepress-demo-preview/plugin@1.4.1(markdown-it-container@3.0.0)(vitepress@1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(terser@5.51.2)(typescript@5.9.3))(vue@3.5.43(typescript@5.9.3))': + '@vitepress-demo-preview/plugin@1.4.1(markdown-it-container@3.0.0)(vitepress@1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(sortablejs@1.15.7)(terser@5.51.2)(typescript@5.9.3))(vue@3.5.43(typescript@5.9.3))': dependencies: '@flypeng/tool': 5.7.5 markdown-it: 14.3.2 markdown-it-container: 3.0.0 - vitepress: 1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(terser@5.51.2)(typescript@5.9.3) + vitepress: 1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(sortablejs@1.15.7)(terser@5.51.2)(typescript@5.9.3) vue: 3.5.43(typescript@5.9.3) '@vue/compiler-core@3.5.43': @@ -2811,13 +2814,14 @@ snapshots: transitivePeerDependencies: - typescript - '@vueuse/integrations@12.8.2(focus-trap@7.8.0)(typescript@5.9.3)': + '@vueuse/integrations@12.8.2(focus-trap@7.8.0)(sortablejs@1.15.7)(typescript@5.9.3)': dependencies: '@vueuse/core': 12.8.2(typescript@5.9.3) '@vueuse/shared': 12.8.2(typescript@5.9.3) vue: 3.5.43(typescript@5.9.3) optionalDependencies: focus-trap: 7.8.0 + sortablejs: 1.15.7 transitivePeerDependencies: - typescript @@ -3656,6 +3660,8 @@ snapshots: '@shikijs/vscode-textmate': 10.0.2 '@types/hast': 3.0.5 + sortablejs@1.15.7: {} + source-map-js@1.2.1: {} source-map-support@0.5.21: @@ -3697,19 +3703,20 @@ snapshots: tabbable@6.5.0: {} - tdesign-icons-vue-next@0.4.11(vue@3.5.43(typescript@5.9.3)): + tdesign-icons-vue-next@0.4.12(vue@3.5.43(typescript@5.9.3)): dependencies: '@babel/runtime': 7.29.7 vue: 3.5.43(typescript@5.9.3) - tdesign-mobile-vue@1.17.1(vue@3.5.43(typescript@5.9.3)): + tdesign-mobile-vue@1.17.2(vue@3.5.43(typescript@5.9.3)): dependencies: '@babel/runtime': 7.29.7 '@use-gesture/vanilla': 10.3.1 '@vueuse/core': 10.7.0(vue@3.5.43(typescript@5.9.3)) dayjs: 1.11.23 lodash-es: 4.18.1 - tdesign-icons-vue-next: 0.4.11(vue@3.5.43(typescript@5.9.3)) + sortablejs: 1.15.7 + tdesign-icons-vue-next: 0.4.12(vue@3.5.43(typescript@5.9.3)) tinycolor2: 1.6.0 validator: 13.15.35 vue: 3.5.43(typescript@5.9.3) @@ -3897,7 +3904,7 @@ snapshots: less: 4.9.1 terser: 5.51.2 - vitepress@1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(terser@5.51.2)(typescript@5.9.3): + vitepress@1.6.4(@algolia/client-search@5.59.0)(@types/node@25.9.8)(less@4.9.1)(postcss@8.5.28)(search-insights@2.17.3)(sortablejs@1.15.7)(terser@5.51.2)(typescript@5.9.3): dependencies: '@docsearch/css': 3.8.2 '@docsearch/js': 3.8.2(@algolia/client-search@5.59.0)(search-insights@2.17.3) @@ -3910,7 +3917,7 @@ snapshots: '@vue/devtools-api': 7.7.10 '@vue/shared': 3.5.43 '@vueuse/core': 12.8.2(typescript@5.9.3) - '@vueuse/integrations': 12.8.2(focus-trap@7.8.0)(typescript@5.9.3) + '@vueuse/integrations': 12.8.2(focus-trap@7.8.0)(sortablejs@1.15.7)(typescript@5.9.3) focus-trap: 7.8.0 mark.js: 8.11.1 minisearch: 7.2.0 diff --git a/package.json b/package.json index 4ca7c79..5d7927f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "**/*.css" ], "private": false, - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "scripts": { "dev": "pnpm run -C docs dev", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9dc18f7..f968d2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4829,8 +4829,8 @@ packages: resolution: {integrity: sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==} engines: {node: '>=6'} - tdesign-icons-vue-next@0.4.11: - resolution: {integrity: sha512-lBkRUy8bdb6lQLFOOkSb1LPdl4CmZRewrc8SOUlmWkDD/DG3BTsSd/ZQ4Z767pPSlypyvxwSwcJgRv6+zjubAQ==} + tdesign-icons-vue-next@0.4.12: + resolution: {integrity: sha512-isuKOIBdOdQCCeWDiOfvdZSucXa0KC6wLBy2YvNLpRZhVxL7SjDVTulCncehzt4JFzi81LI0+dCVohw6GbfjPA==} peerDependencies: vue: ^3.0.0 @@ -10629,7 +10629,7 @@ snapshots: tapable@2.2.1: {} - tdesign-icons-vue-next@0.4.11(vue@3.5.26(typescript@5.8.3)): + tdesign-icons-vue-next@0.4.12(vue@3.5.26(typescript@5.8.3)): dependencies: '@babel/runtime': 7.26.9 vue: 3.5.26(typescript@5.8.3) @@ -10642,7 +10642,7 @@ snapshots: dayjs: 1.11.13 lodash-es: 4.17.21 sortablejs: 1.15.7 - tdesign-icons-vue-next: 0.4.11(vue@3.5.26(typescript@5.8.3)) + tdesign-icons-vue-next: 0.4.12(vue@3.5.26(typescript@5.8.3)) tinycolor2: 1.6.0 validator: 13.12.0 vue: 3.5.26(typescript@5.8.3) diff --git a/src/components/ai/AiChatComposer.vue b/src/components/ai/AiChatComposer.vue index e4a3c08..5e6603f 100644 --- a/src/components/ai/AiChatComposer.vue +++ b/src/components/ai/AiChatComposer.vue @@ -1,5 +1,5 @@ @@ -352,15 +420,20 @@ onBeforeUnmount(() => { margin: .5rem 0 0; display: flex; padding: .5rem; + position: relative; box-shadow: 0 .5rem 1.5rem rgba(15, 23, 42, .12); + transition: border-color .2s, box-shadow .2s; align-items: stretch; border-radius: 1.25rem; flex-direction: column; .input-wrap { + gap: .375rem; + display: flex; position: relative; flex: 1; min-width: 0; + flex-direction: column; } .input { @@ -368,80 +441,118 @@ onBeforeUnmount(() => { width: 100%; padding: 0 .25rem; min-width: 0; + + &.voice-input-hidden { + visibility: hidden; + } } - .voice-hit { - inset: 0; - z-index: 1; - position: absolute; - touch-action: none; - -webkit-tap-highlight-color: transparent; - } - - .voice-panel { - inset: 0; - gap: .25rem; + .voice-transcript { + left: 50%; + gap: .5rem; + width: 100%; + z-index: 3; display: flex; - z-index: 2; padding: .5rem .75rem; position: absolute; - user-select: none; - border-radius: .75rem; + box-sizing: border-box; + bottom: calc(100% + .5rem); + align-items: center; pointer-events: none; + border: 1px solid var(--td-brand-color); background: var(--td-bg-color-container); + box-shadow: 0 .5rem 1.5rem rgba(15, 23, 42, .16); + animation: voice-transcript-in .16s ease-out; + border-radius: 1rem; + transform: translateX(-50%); + } + + .voice-wave { + gap: .1875rem; + height: 1rem; + display: flex; + flex: none; + align-items: center; + + span { + width: .125rem; + height: 100%; + border-radius: .125rem; + background: var(--td-brand-color); + animation: voice-wave .9s ease-in-out infinite; + animation-delay: calc(var(--i) * .1s); + transform: scaleY(.3); + transform-origin: center; + } + } + + .voice-text, + .voice-placeholder { + margin: 0; + flex: 1; + min-width: 0; + word-break: break-word; + } + + .voice-text { + display: -webkit-box; + overflow: hidden; + color: var(--td-text-color-primary); + font-size: .875rem; + line-height: 1.4; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + } + + .voice-placeholder { + overflow: hidden; + color: var(--td-text-color-placeholder); + font-size: .75rem; + white-space: nowrap; + text-overflow: ellipsis; + } + + .voice-hold { + inset: 0; + gap: .375rem; + z-index: 1; + display: flex; + padding: 0 .75rem; + position: absolute; + color: var(--td-brand-color); + font-size: .875rem; + font-weight: 500; + transition: color .15s, border-color .15s; + border: 0; + border-bottom: 1px solid var(--td-component-border); + background: transparent; + border-radius: 0; align-items: center; - flex-direction: column; justify-content: center; + touch-action: none; + user-select: none; + -webkit-tap-highlight-color: transparent; - .voice-wave { - gap: .1875rem; - height: 1.25rem; - display: flex; - align-items: center; - - span { - width: .1875rem; - height: 30%; - border-radius: .125rem; - background: var(--td-brand-color); - animation: voice-wave .9s ease-in-out infinite; - animation-delay: calc(var(--i) * .1s); - } - } - - .voice-text { - overflow: hidden; - margin: .375rem 0 0; - font-size: .8125rem; - text-align: center; - line-height: 1.4; - display: -webkit-box; - -webkit-box-orient: vertical; - -webkit-line-clamp: 2; - } - - .voice-hint { - margin: .25rem 0 0; - color: var(--td-text-color-secondary); - font-size: .6875rem; + &.active { + color: var(--td-brand-color); + border-bottom-color: var(--td-brand-color); } &.cancel { - .voice-text, - .voice-hint { - color: var(--td-error-color); - } + color: var(--td-error-color); + border-bottom-color: var(--td-error-color); + } - .voice-wave span { - background: var(--td-error-color); - } + &:disabled { + opacity: .55; } } .actions { - --td-button-border-radius: .75rem; + --td-button-border-radius: 1rem; gap: .5rem; + min-height: 2rem; margin-top: .375rem; display: flex; align-items: center; @@ -452,23 +563,58 @@ onBeforeUnmount(() => { display: flex; align-items: center; } - - .send { - padding: 0 1rem; - } } } + + &.voice-active .form { + border-color: var(--td-brand-color); + + &::after { + content: ""; + inset: -.125rem; + border: 1px solid var(--td-brand-color); + position: absolute; + animation: voice-breathe 1s ease-in-out 0s infinite; + will-change: transform, opacity; + border-radius: inherit; + pointer-events: none; + transform-origin: center; + } + } +} + +@keyframes voice-breathe { + 0%, + 100% { + opacity: .6; + transform: scaleX(1) scaleY(1); + } + + 50% { + opacity: .2; + transform: scaleX(1.02) scaleY(1.08); + } } @keyframes voice-wave { 0%, 100% { - height: 25%; opacity: .5; + transform: scaleY(.3); } 50% { - height: 100%; + opacity: 1; + transform: scaleY(1); + } +} + +@keyframes voice-transcript-in { + from { + opacity: 0; + } + + to { opacity: 1; } }