feat(ui): implement voice interaction and enhanced home page animations

Introduces a comprehensive voice interaction system and upgrades the home page
experience with dynamic typing effects and improved layout transitions.

Key changes:
- Added `MicrophoneService` for managing media stream lifecycle and permissions.
- Added `SpeechRecognitionService` for continuous speech-to-text processing.
- Added `VoiceOrbService` using Three.js to render an animated audio-reactive
  orb.
- Enhanced `HomePage` with a randomized typing effect for welcome titles
  and improved state management for message transitions.
- Refactored `AiChatInputComponent` to support seamless switching between
  text composer and voice recording modes.
- Improved `SidebarComponent` navigation logic and styling.
- Updated global styles and component CSS for better theme consistency
  and smoother animations.
This commit is contained in:
PeymanHonarjoo
2026-10-06 17:27:52 +03:30
parent 3a0001c30d
commit d22cd65e28
16 changed files with 1736 additions and 478 deletions
@@ -1,24 +1,25 @@
<div class="ai-chat-input-wrapper" [class.voice-active]="isVoiceMode()">
<div class="composer-layer" [class.layer-hidden]="isVoiceMode()">
<div
class="ai-chat-input-wrapper"
[class.voice-active]="isVoiceMode()"
[attr.data-voice-state]="voiceState()"
(keydown.escape)="onEscape()"
>
<!-- Announces every voice state change to screen readers -->
<div class="sr-only" role="status" aria-live="polite">{{ statusText() }}</div>
<div class="composer-layer" [attr.inert]="isVoiceMode() ? '' : null">
<div class="chat-composer" #composer>
<button
#plusBtn
type="button"
class="composer-btn plus-btn"
(click)="toggleAttachmentMenu()"
[attr.aria-expanded]="isAttachmentMenuOpen()"
aria-label="افزودن پیوست"
aria-haspopup="menu"
aria-controls="attachment-menu"
[attr.aria-expanded]="isAttachmentMenuOpen()"
>
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M12 5v14M5 12h14" />
</svg>
</button>
@@ -40,20 +41,17 @@
<button
type="button"
class="composer-btn mic-btn"
[class.is-pending]="voiceState() === 'requesting-permission'"
[class.is-unsupported]="!voiceSupported"
[disabled]="disabled()"
[attr.aria-label]="micLabel()"
[attr.title]="micLabel()"
[attr.aria-pressed]="isVoiceMode()"
[attr.aria-busy]="voiceState() === 'requesting-permission'"
[attr.aria-disabled]="voiceSupported ? null : 'true'"
(click)="toggleVoiceMode()"
aria-label="حالت صوتی"
>
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" />
<path d="M19 10v2a7 7 0 0 1-14 0v-2" />
<line x1="12" x2="12" y1="19" y2="22" />
@@ -67,68 +65,45 @@
(click)="sendMessage()"
aria-label="ارسال پیام"
>
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M12 19V5M5 12l7-7 7 7" />
</svg>
</button>
@if (isAttachmentMenuOpen()) {
<div class="attachment-menu" role="menu">
<button
type="button"
class="attachment-menu-item"
role="menuitem"
(click)="selectFile(); closeAttachmentMenu();"
>
<svg
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
<div
#attachmentMenu
id="attachment-menu"
class="attachment-menu"
role="menu"
aria-label="پیوست‌ها"
(keydown)="onMenuKeydown($event)"
>
@for (action of attachmentActions(); track action.id) {
<button
type="button"
class="attachment-menu-item"
role="menuitem"
(click)="selectAction(action)"
>
<path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z" />
<polyline points="14 2 14 8 20 8" />
</svg>
<span>آپلود فایل</span>
</button>
<button
type="button"
class="attachment-menu-item"
role="menuitem"
(click)="selectFile(); closeAttachmentMenu();"
>
<svg
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
<circle cx="8.5" cy="8.5" r="1.5" />
<polyline points="21 15 16 10 5 21" />
</svg>
<span>آپلود تصویر</span>
</button>
@switch (action.icon) {
@case ('image') {
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
<circle cx="8.5" cy="8.5" r="1.5" />
<polyline points="21 15 16 10 5 21" />
</svg>
}
@default {
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z" />
<polyline points="14 2 14 8 20 8" />
</svg>
}
}
<span>{{ action.label }}</span>
</button>
}
</div>
}
@@ -136,38 +111,84 @@
#fileInput
type="file"
class="sr-only"
tabindex="-1"
(change)="onFileChange($event)"
aria-hidden="true"
/>
</div>
@if (notice(); as n) {
<div
class="voice-notice"
[class.is-error]="n.kind === 'error'"
[attr.role]="n.kind === 'error' ? 'alert' : 'status'"
>
<span class="voice-notice-text">{{ n.text }}</span>
<button type="button" class="voice-notice-close" aria-label="بستن پیام" (click)="dismissNotice()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" x2="6" y1="6" y2="18" />
<line x1="6" x2="18" y1="6" y2="18" />
</svg>
</button>
</div>
}
</div>
<div class="voice-layer" [class.layer-hidden]="!isVoiceMode()">
<div class="voice-mode" #voiceContainer>
<div class="orb-container" #orbContainer></div>
<p class="voice-mode-text">در حال گوش دادن...</p>
<button
type="button"
class="voice-stop-btn"
(click)="exitVoiceMode()"
aria-label="خروج از حالت صوتی"
>
<svg
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
<div
class="voice-layer"
[attr.inert]="isVoiceMode() ? null : ''"
[attr.aria-hidden]="isVoiceMode() ? null : 'true'"
>
<div class="voice-mode" role="region" aria-label="حالت صوتی">
<div class="orb-container" #orbContainer aria-hidden="true">
@if (!orbAvailable()) {
<div class="orb-fallback"></div>
}
</div>
<div class="voice-status" [class.is-speaking]="voiceState() === 'transcribing'">
<span class="rec-dot" aria-hidden="true"></span>
<p class="voice-mode-text">{{ statusText() }}</p>
</div>
<div class="voice-transcript" #transcript dir="rtl">
@if (liveFinal() || liveInterim()) {
<span class="t-final">{{ liveFinal() }}</span>
@if (liveInterim()) {
<span class="t-interim"> {{ liveInterim() }}</span>
}
} @else {
<span class="t-placeholder">صحبت کنید؛ متن اینجا نمایش داده می‌شود</span>
}
</div>
<div class="voice-actions">
<button
type="button"
class="voice-stop-btn is-primary"
[disabled]="voiceState() === 'stopping'"
(click)="stopVoice(true)"
aria-label="پایان ضبط و ویرایش متن"
>
<line x1="18" x2="6" y1="6" y2="18" />
<line x1="6" x2="18" y1="6" y2="18" />
</svg>
<span>پایان گفتگو</span>
</button>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<rect x="6" y="6" width="12" height="12" rx="2" />
</svg>
<span>پایان و ویرایش</span>
</button>
<button
type="button"
class="voice-stop-btn"
[disabled]="voiceState() === 'stopping'"
(click)="stopVoice(false)"
aria-label="لغو ضبط و حذف متن گفتاری"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" x2="6" y1="6" y2="18" />
<line x1="6" x2="18" y1="6" y2="18" />
</svg>
<span>لغو</span>
</button>
</div>
</div>
</div>
</div>
</div>