feat(ui): implement home page and ai chat input with voice orb

Implement the core user interface components including the home page,
a sophisticated AI chat input component, and a 3D voice visualization
service using Three.js.

- Add `HomePage` component with responsive layout and theme integration.
- Add `AiChatInputComponent` supporting text, file attachments, and
  voice mode transitions.
- Implement `VoiceOrbService` using Three.js to provide a reactive
  3D animated orb for voice interaction.
- Update routing to include the new home page.
- Refactor `SettingsPage` to clean up unused RTL logic and improve
  UI styling.
- Adjust Angular build budgets in `angular.json` to accommodate
  increased bundle size from Three.js.
This commit is contained in:
PeymanHonarjoo
2026-10-06 12:03:02 +03:30
parent 268a431c1e
commit 3a0001c30d
12 changed files with 1160 additions and 30 deletions
@@ -0,0 +1,347 @@
.ai-chat-input-wrapper {
width: 100%;
max-width: 800px;
margin: 0 auto;
position: relative;
min-height: 72px;
}
.ai-chat-input-wrapper.voice-active {
min-height: 380px;
}
/* Layers transition */
.composer-layer,
.voice-layer {
transition: opacity 0.35s ease, transform 0.35s ease;
}
.composer-layer {
position: relative;
opacity: 1;
transform: translateY(0);
pointer-events: auto;
}
.voice-layer {
position: absolute;
inset: 0;
opacity: 0;
transform: translateY(10px);
pointer-events: none;
}
.ai-chat-input-wrapper.voice-active .composer-layer {
opacity: 0;
transform: translateY(10px);
pointer-events: none;
}
.ai-chat-input-wrapper.voice-active .voice-layer {
position: relative;
opacity: 1;
transform: translateY(0);
pointer-events: auto;
}
/* Chat Composer */
.chat-composer {
display: flex;
align-items: flex-end;
gap: 0.375rem;
padding: 0.625rem 0.75rem;
background: var(--surface-bg);
border: 1px solid var(--surface-border);
border-radius: 1.5rem;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
transition: box-shadow 0.2s ease, border-color 0.2s ease;
position: relative;
}
.chat-composer:focus-within {
border-color: var(--color-primary);
box-shadow: 0 4px 20px rgba(59, 130, 246, 0.12), 0 1px 3px rgba(0, 0, 0, 0.03);
}
/* Textarea */
.composer-textarea-wrapper {
flex: 1;
min-width: 0;
}
.composer-textarea {
width: 100%;
min-height: 24px;
max-height: 192px;
padding: 0.375rem 0;
border: none;
background: transparent;
color: var(--app-text);
font-family: inherit;
font-size: 0.9375rem;
line-height: 1.6;
resize: none;
outline: none;
text-align: right;
direction: rtl;
overflow-y: auto;
}
.composer-textarea::placeholder {
color: var(--muted);
text-align: right;
opacity: 0.8;
}
.composer-textarea:disabled {
opacity: 0.6;
cursor: not-allowed;
}
/* Remove scrollbar but keep functionality */
.composer-textarea::-webkit-scrollbar {
width: 4px;
}
.composer-textarea::-webkit-scrollbar-thumb {
background: var(--muted);
border-radius: 9999px;
opacity: 0.3;
}
/* Action Buttons */
.composer-btn {
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border: none;
border-radius: 50%;
background: transparent;
color: var(--muted);
cursor: pointer;
transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
flex-shrink: 0;
user-select: none;
}
.composer-btn:hover:not(:disabled) {
background: var(--sidebar-hover);
color: var(--text-primary);
transform: scale(1.05);
}
.composer-btn:active:not(:disabled) {
transform: scale(0.95);
}
.composer-btn:disabled {
opacity: 0.35;
cursor: not-allowed;
}
.composer-btn:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
.send-btn {
background: var(--color-primary);
color: #ffffff;
}
.send-btn:hover:not(:disabled) {
background: #2563eb;
color: #ffffff;
}
/* Attachment Menu */
.attachment-menu {
position: absolute;
bottom: calc(100% + 0.5rem);
right: 0.5rem;
min-width: 180px;
background: var(--surface-bg);
border: 1px solid var(--surface-border);
border-radius: 0.875rem;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
overflow: hidden;
z-index: 50;
animation: menuFadeIn 0.15s ease;
}
.attachment-menu-item {
display: flex;
align-items: center;
gap: 0.625rem;
width: 100%;
padding: 0.625rem 1rem;
border: none;
background: transparent;
color: var(--text-secondary);
font-family: inherit;
font-size: 0.875rem;
text-align: right;
cursor: pointer;
transition: background 0.15s ease;
}
.attachment-menu-item:hover {
background: var(--sidebar-hover);
color: var(--text-primary);
}
.attachment-menu-item:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: -2px;
background: var(--sidebar-hover);
}
@keyframes menuFadeIn {
from {
opacity: 0;
transform: translateY(4px) scale(0.97);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
/* Voice Mode */
.voice-mode {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 1.25rem;
padding: 1.5rem;
background: var(--surface-bg);
border: 1px solid var(--surface-border);
border-radius: 1.5rem;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
min-height: 320px;
}
.orb-container {
width: 260px;
height: 260px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.orb-container canvas {
display: block;
width: 100% !important;
height: 100% !important;
}
.voice-mode-text {
font-size: 0.9375rem;
color: var(--text-secondary);
margin: 0;
text-align: center;
}
.voice-stop-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.625rem 1.25rem;
border: 1px solid var(--surface-border);
border-radius: 9999px;
background: var(--surface-bg);
color: var(--text-secondary);
font-family: inherit;
font-size: 0.875rem;
cursor: pointer;
transition: all 0.2s ease;
user-select: none;
}
.voice-stop-btn:hover {
background: #ef4444;
color: #ffffff;
border-color: #ef4444;
transform: scale(1.03);
}
.voice-stop-btn:active {
transform: scale(0.97);
}
.voice-stop-btn:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
/* Screen reader only */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
.composer-layer,
.voice-layer,
.chat-composer,
.composer-btn,
.voice-stop-btn,
.attachment-menu {
transition: none !important;
animation: none !important;
}
}
/* Mobile responsiveness */
@media (max-width: 640px) {
.ai-chat-input-wrapper {
max-width: 100%;
}
.chat-composer {
gap: 0.25rem;
padding: 0.5rem 0.625rem;
border-radius: 1.25rem;
}
.composer-btn {
width: 32px;
height: 32px;
}
.composer-btn svg {
width: 18px;
height: 18px;
}
.composer-textarea {
font-size: 0.875rem;
}
.orb-container {
width: 200px;
height: 200px;
}
.voice-mode {
min-height: 280px;
gap: 1rem;
}
.attachment-menu {
right: 0.25rem;
min-width: 160px;
}
}
@@ -0,0 +1,173 @@
<div class="ai-chat-input-wrapper" [class.voice-active]="isVoiceMode()">
<div class="composer-layer" [class.layer-hidden]="isVoiceMode()">
<div class="chat-composer" #composer>
<button
type="button"
class="composer-btn plus-btn"
(click)="toggleAttachmentMenu()"
[attr.aria-expanded]="isAttachmentMenuOpen()"
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 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"
(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"
>
<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 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"
>
<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>
</div>
}
<input
#fileInput
type="file"
class="sr-only"
(change)="onFileChange($event)"
aria-hidden="true"
/>
</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"
>
<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>
@@ -0,0 +1,177 @@
import {
ChangeDetectionStrategy,
Component,
input,
output,
signal,
ViewChild,
ElementRef,
AfterViewChecked,
OnInit,
OnDestroy,
inject,
} from '@angular/core';
import { CommonModule } from '@angular/common';
import { VoiceOrbService } from '../../../services/voice-orb/voice-orb.service';
@Component({
selector: 'app-ai-chat-input',
standalone: true,
imports: [CommonModule],
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './ai-chat-input.component.html',
styleUrl: './ai-chat-input.component.css',
})
export class AiChatInputComponent implements AfterViewChecked, OnInit, OnDestroy {
private readonly voiceOrbService = inject(VoiceOrbService);
readonly placeholder = input<string>('پیام خود را بنویسید...');
readonly disabled = input<boolean>(false);
readonly messageSent = output<string>();
readonly fileSelected = output<File>();
readonly voiceToggled = output<boolean>();
readonly message = signal('');
readonly isVoiceMode = signal(false);
readonly isAttachmentMenuOpen = signal(false);
@ViewChild('textarea') textareaRef!: ElementRef<HTMLTextAreaElement>;
@ViewChild('composer') composerRef!: ElementRef<HTMLDivElement>;
@ViewChild('voiceContainer') voiceContainerRef!: ElementRef<HTMLDivElement>;
@ViewChild('orbContainer') orbContainerRef!: ElementRef<HTMLDivElement>;
@ViewChild('fileInput') fileInputRef!: ElementRef<HTMLInputElement>;
private orbInited = false;
private menuCloseHandler: ((event: MouseEvent) => void) | null = null;
private escapeHandler: ((event: KeyboardEvent) => void) | null = null;
selectFile(): void {
this.fileInputRef?.nativeElement.click();
}
ngOnInit(): void {
this.attachDocumentListeners();
}
ngAfterViewChecked(): void {
if (this.isVoiceMode() && !this.orbInited && this.orbContainerRef) {
this.orbInited = true;
this.voiceOrbService.init(this.orbContainerRef.nativeElement);
this.voiceOrbService.resetOrbGeometry();
this.voiceOrbService.startAnimation();
this.voiceOrbService.startListening().catch(() => {
/* orb continues without audio reactivity */
});
}
}
ngOnDestroy(): void {
this.detachDocumentListeners();
this.voiceOrbService.dispose();
}
onTextareaInput(): void {
const textarea = this.textareaRef?.nativeElement;
if (!textarea) return;
this.message.set(textarea.value);
textarea.style.height = 'auto';
const scrollHeight = textarea.scrollHeight;
const maxHeight = 192;
const newHeight = Math.min(scrollHeight, maxHeight);
textarea.style.height = newHeight + 'px';
}
onKeyDown(event: KeyboardEvent): void {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
this.sendMessage();
}
}
sendMessage(): void {
const text = this.message().trim();
if (!text) return;
this.messageSent.emit(text);
this.message.set('');
const textarea = this.textareaRef?.nativeElement;
if (textarea) {
textarea.value = '';
textarea.style.height = 'auto';
}
}
toggleAttachmentMenu(): void {
this.isAttachmentMenuOpen.update((open) => !open);
}
closeAttachmentMenu(): void {
this.isAttachmentMenuOpen.set(false);
}
onFileChange(event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (file) {
this.fileSelected.emit(file);
}
if (input.value) {
input.value = '';
}
this.closeAttachmentMenu();
}
toggleVoiceMode(): void {
if (this.isVoiceMode()) {
this.exitVoiceMode();
} else {
this.enterVoiceMode();
}
}
private enterVoiceMode(): void {
this.isVoiceMode.set(true);
this.orbInited = false;
this.voiceToggled.emit(true);
}
exitVoiceMode(): void {
this.voiceOrbService.stopAnimation();
this.voiceOrbService.stopListening();
this.isVoiceMode.set(false);
this.voiceToggled.emit(false);
}
private attachDocumentListeners(): void {
this.menuCloseHandler = (event: MouseEvent) => {
if (!this.isAttachmentMenuOpen()) return;
const target = event.target as Node;
if (this.composerRef && this.composerRef.nativeElement.contains(target)) {
return;
}
this.closeAttachmentMenu();
};
this.escapeHandler = (event: KeyboardEvent) => {
if (event.key === 'Escape' && this.isAttachmentMenuOpen()) {
this.closeAttachmentMenu();
}
};
document.addEventListener('mousedown', this.menuCloseHandler);
document.addEventListener('keydown', this.escapeHandler);
}
private detachDocumentListeners(): void {
if (this.menuCloseHandler) {
document.removeEventListener('mousedown', this.menuCloseHandler);
}
if (this.escapeHandler) {
document.removeEventListener('keydown', this.escapeHandler);
}
}
}