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:
@@ -3,19 +3,69 @@
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100%;
|
||||
min-height: 100vh;
|
||||
padding: 2rem 1rem;
|
||||
transition: padding 0.4s ease;
|
||||
position: relative;
|
||||
background:
|
||||
radial-gradient(ellipse 50% 40% at 50% 45%, rgba(59, 130, 246, 0.1), transparent 70%),
|
||||
var(--app-bg);
|
||||
}
|
||||
|
||||
.home-page::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background:
|
||||
radial-gradient(circle at 50% 40%, rgba(59, 130, 246, 0.07), transparent 55%),
|
||||
radial-gradient(circle at 35% 55%, rgba(99, 102, 241, 0.05), transparent 50%),
|
||||
radial-gradient(circle at 65% 50%, rgba(59, 130, 246, 0.04), transparent 45%);
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.home-page > .home-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.home-page.has-messages {
|
||||
justify-content: flex-end;
|
||||
padding-bottom: 2rem;
|
||||
background: var(--app-bg);
|
||||
}
|
||||
|
||||
.home-page.has-messages::before {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.home-header {
|
||||
position: absolute;
|
||||
top: 2rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
text-align: center;
|
||||
transition:
|
||||
opacity 0.35s ease,
|
||||
transform 0.35s ease,
|
||||
margin 0.35s ease;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.home-page.has-messages .home-header {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(-8px);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-page.has-messages .home-title {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-content {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.home-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.home-icon-wrapper {
|
||||
@@ -38,18 +88,57 @@
|
||||
}
|
||||
|
||||
.home-title {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 600;
|
||||
width: 100%;
|
||||
margin: 0 0 1rem;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
text-align: center;
|
||||
direction: rtl;
|
||||
|
||||
font-size: 1.5rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 0.5rem;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.home-subtitle {
|
||||
font-size: 0.9375rem;
|
||||
color: var(--text-muted);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
.home-title-text {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.cursor {
|
||||
display: inline-block;
|
||||
|
||||
width: 2px;
|
||||
height: 1.15em;
|
||||
|
||||
margin-right: 3px;
|
||||
|
||||
background-color: var(--text-primary);
|
||||
|
||||
border-radius: 1px;
|
||||
|
||||
animation: cursorBlink 0.8s ease-in-out infinite;
|
||||
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.cursor-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@keyframes cursorBlink {
|
||||
0%,
|
||||
45% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
46%,
|
||||
100% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
@@ -57,14 +146,17 @@
|
||||
padding: 1.25rem 0.75rem;
|
||||
}
|
||||
|
||||
.home-page.has-messages {
|
||||
padding-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.home-header {
|
||||
margin-bottom: 1.25rem;
|
||||
top: 1.25rem;
|
||||
}
|
||||
|
||||
.home-icon-wrapper {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin-bottom: 1.25rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
@@ -76,10 +168,6 @@
|
||||
.home-title {
|
||||
font-size: 1.375rem;
|
||||
}
|
||||
|
||||
.home-subtitle {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
@@ -90,3 +178,14 @@
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeInUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,36 @@
|
||||
<div class="home-page">
|
||||
<div class="home-content">
|
||||
<div class="home-header">
|
||||
<div class="home-icon-wrapper">
|
||||
<img
|
||||
class="home-logo"
|
||||
[src]="logoSrc()"
|
||||
alt="Raymand"
|
||||
/>
|
||||
</div>
|
||||
<h1 class="home-title">دستیار هوشمند</h1>
|
||||
<p class="home-subtitle">سوال خود را بپرسید، من اینجا هستم</p>
|
||||
<div class="home-page" [class.has-messages]="hasMessages()">
|
||||
|
||||
<div class="home-header" [class.header-hidden]="hasMessages()">
|
||||
<div class="home-icon-wrapper">
|
||||
<img
|
||||
class="home-logo"
|
||||
[src]="logoSrc()"
|
||||
alt="Raymand"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="home-content">
|
||||
|
||||
<h1 class="home-title">
|
||||
<span class="home-title-text">
|
||||
{{ streamedText() }}
|
||||
</span>
|
||||
|
||||
<span
|
||||
class="cursor"
|
||||
[class.cursor-hidden]="!isStreaming()"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
</h1>
|
||||
|
||||
<app-ai-chat-input
|
||||
placeholder="پیام خود را بنویسید..."
|
||||
[hasMessages]="hasMessages()"
|
||||
(messageSent)="onMessageSent($event)"
|
||||
(fileSelected)="onFileSelected($event)"
|
||||
(voiceToggled)="onVoiceToggled($event)"
|
||||
/>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,7 +1,30 @@
|
||||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
inject,
|
||||
signal,
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AiChatInputComponent } from '../../shared/ui/ai-chat-input/ai-chat-input.component';
|
||||
import { Router, NavigationEnd } from '@angular/router';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { ThemeService } from '../../services/theme/theme.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
const HOME_TITLES = [
|
||||
'چه چیزی میخواهید بدانید؟...',
|
||||
'سوالتان را بپرسید، با شما هستم...',
|
||||
'هر سوالی دارید، از من بپرسید...',
|
||||
'از هر چیزی که میخواهید شروع کنید...',
|
||||
'سوالتان را مطرح کنید، پاسخ میدهم...',
|
||||
'بپرسید؛ با هم به پاسخ میرسیم...',
|
||||
'هر سوالی در ذهن دارید، بپرسید...',
|
||||
'دنبال یک پاسخ دقیق هستید؟...',
|
||||
'سوالتان را همینجا مطرح کنید...',
|
||||
'آمادهام به سوالتان پاسخ بدهم...',
|
||||
];
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -11,14 +34,92 @@ import { ThemeService } from '../../services/theme/theme.service';
|
||||
templateUrl: './home.page.html',
|
||||
styleUrl: './home.page.css',
|
||||
})
|
||||
export class HomePage {
|
||||
export class HomePage implements OnInit, OnDestroy {
|
||||
private readonly themeService = inject(ThemeService);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
readonly isDarkMode = this.themeService.isDarkMode;
|
||||
|
||||
readonly logoSrc = () => this.isDarkMode() ? 'assets/images/RaymandLogo.png' : 'assets/images/login.png';
|
||||
readonly logoSrc = () =>
|
||||
this.isDarkMode() ? 'assets/images/RaymandLogo.png' : 'assets/images/login.png';
|
||||
|
||||
readonly hasMessages = signal(false);
|
||||
|
||||
readonly homeTitle = signal('');
|
||||
readonly streamedText = signal('');
|
||||
readonly isStreaming = signal(false);
|
||||
|
||||
private typingTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private routerSubscription?: Subscription;
|
||||
|
||||
constructor() {
|
||||
this.routerSubscription = this.router.events
|
||||
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||
.subscribe((event: NavigationEnd) => {
|
||||
if (event.url === '/' || event.url === '') {
|
||||
this.hasMessages.set(false);
|
||||
this.setRandomTitle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.setRandomTitle();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.stopTyping();
|
||||
this.routerSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
private setRandomTitle(): void {
|
||||
this.stopTyping();
|
||||
|
||||
const index = Math.floor(Math.random() * HOME_TITLES.length);
|
||||
const title = HOME_TITLES[index];
|
||||
|
||||
this.homeTitle.set(title);
|
||||
this.startTyping(title);
|
||||
}
|
||||
|
||||
private startTyping(text: string): void {
|
||||
this.streamedText.set('');
|
||||
this.isStreaming.set(true);
|
||||
|
||||
let index = 0;
|
||||
|
||||
const typeNextCharacter = () => {
|
||||
if (index >= text.length) {
|
||||
this.streamedText.set(text);
|
||||
this.isStreaming.set(false);
|
||||
this.typingTimer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
this.streamedText.set(text.substring(0, index));
|
||||
|
||||
// Slightly random timing makes it feel more natural
|
||||
const delay = 12 + Math.random() * 8;
|
||||
|
||||
this.typingTimer = setTimeout(typeNextCharacter, delay);
|
||||
};
|
||||
|
||||
typeNextCharacter();
|
||||
}
|
||||
|
||||
private stopTyping(): void {
|
||||
if (this.typingTimer !== null) {
|
||||
clearTimeout(this.typingTimer);
|
||||
this.typingTimer = null;
|
||||
}
|
||||
|
||||
this.isStreaming.set(false);
|
||||
}
|
||||
|
||||
onMessageSent(message: string): void {
|
||||
this.hasMessages.set(true);
|
||||
console.log('Message sent:', message);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user