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.
194 lines
7.1 KiB
HTML
194 lines
7.1 KiB
HTML
<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()"
|
|
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">
|
|
<path d="M12 5v14M5 12h14" />
|
|
</svg>
|
|
</button>
|
|
|
|
<div class="composer-textarea-wrapper">
|
|
<textarea
|
|
#textarea
|
|
class="composer-textarea"
|
|
[placeholder]="placeholder()"
|
|
[disabled]="disabled()"
|
|
(input)="onTextareaInput()"
|
|
(keydown)="onKeyDown($event)"
|
|
rows="1"
|
|
dir="rtl"
|
|
aria-label="متن پیام"
|
|
></textarea>
|
|
</div>
|
|
|
|
<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()"
|
|
>
|
|
<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" />
|
|
</svg>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
class="composer-btn send-btn"
|
|
[disabled]="!message().trim() || disabled()"
|
|
(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">
|
|
<path d="M12 19V5M5 12l7-7 7 7" />
|
|
</svg>
|
|
</button>
|
|
|
|
@if (isAttachmentMenuOpen()) {
|
|
<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)"
|
|
>
|
|
@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>
|
|
}
|
|
|
|
<input
|
|
#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"
|
|
[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="پایان ضبط و ویرایش متن"
|
|
>
|
|
<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> |