-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
619 lines (526 loc) · 20.9 KB
/
script.js
File metadata and controls
619 lines (526 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/**
* Chetech AB Website - Interactive Scripts
* Terminal animation and UI interactions
*/
(function() {
'use strict';
// ===================================
// Terminal Animation Configuration
// ===================================
const terminalSequences = [
{
command: 'chetech-agent --task "analyze codebase"',
outputs: [
{ text: '> Initializing secure, offline AI environment...', delay: 300 },
{ text: '> Loading local LLM (no cloud dependencies)...', delay: 600 },
{ text: '> Scanning repository structure...', delay: 800 },
{ text: '> Found 247 source files across 12 modules', delay: 400, class: 'info' },
{ text: '> Ready for queries.', delay: 300, class: 'success' }
]
},
{
command: 'chetech-agent --rag "query legacy docs"',
outputs: [
{ text: '> Connecting to RAG pipeline...', delay: 300 },
{ text: '> Indexing 1,247 legacy documentation files...', delay: 700 },
{ text: '> Building semantic embeddings...', delay: 600 },
{ text: '> Vector store ready (local, encrypted)', delay: 400, class: 'info' },
{ text: '> Pipeline operational. Zero data leaves your network.', delay: 400, class: 'success' }
]
},
{
command: 'chetech-agent --refactor "optimize module"',
outputs: [
{ text: '> Analyzing code patterns...', delay: 400 },
{ text: '> Identifying optimization opportunities...', delay: 500 },
{ text: '> Generating refactored code...', delay: 600 },
{ text: '> Running test suite... 47/47 passed', delay: 700, class: 'success' },
{ text: '> Refactoring complete. PR ready for review.', delay: 300, class: 'success' }
]
},
{
command: 'chetech-agent --mcp "connect tools"',
outputs: [
{ text: '> Starting MCP server...', delay: 300 },
{ text: '> Registering tools: git, jira, confluence', delay: 500 },
{ text: '> Establishing secure connections...', delay: 600 },
{ text: '> All tools connected via Model Context Protocol', delay: 400, class: 'info' },
{ text: '> AI assistant now has full tool access.', delay: 300, class: 'success' }
]
}
];
// ===================================
// Terminal Animation Engine
// ===================================
class TerminalAnimator {
constructor() {
this.commandEl = null;
this.outputEl = null;
this.cursorEl = null;
this.currentSequence = 0;
this.isAnimating = false;
this.isPaused = false;
}
setElements(commandEl, outputEl, cursorEl) {
this.commandEl = commandEl;
this.outputEl = outputEl;
this.cursorEl = cursorEl;
}
pause() {
this.isPaused = true;
}
resume() {
this.isPaused = false;
}
async typeText(element, text, speed = 50) {
if (!element) return;
element.textContent = '';
for (let i = 0; i < text.length; i++) {
if (this.isPaused) {
await this.waitForResume();
}
element.textContent += text[i];
await this.sleep(speed);
}
}
async waitForResume() {
while (this.isPaused) {
await this.sleep(100);
}
}
async sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async addOutputLine(text, className = '') {
if (!this.outputEl) return;
const line = document.createElement('div');
line.className = 'output-line' + (className ? ' ' + className : '');
line.textContent = text;
this.outputEl.appendChild(line);
}
async runSequence(sequence) {
if (this.isAnimating || !this.commandEl || !this.outputEl) return;
this.isAnimating = true;
// Clear previous output
this.outputEl.innerHTML = '';
this.commandEl.textContent = '';
// Show cursor
if (this.cursorEl) {
this.cursorEl.style.display = 'inline';
}
// Type command
await this.typeText(this.commandEl, sequence.command, 40);
// Small pause after command
await this.sleep(400);
// Show outputs one by one
for (const output of sequence.outputs) {
if (this.isPaused) {
await this.waitForResume();
}
await this.sleep(output.delay || 300);
await this.addOutputLine(output.text, output.class || '');
}
// Pause before next sequence
await this.sleep(8000);
this.isAnimating = false;
}
async start() {
while (true) {
if (!this.isPaused && this.commandEl && this.outputEl) {
await this.runSequence(terminalSequences[this.currentSequence]);
this.currentSequence = (this.currentSequence + 1) % terminalSequences.length;
} else {
await this.sleep(500);
}
}
}
}
// ===================================
// Terminal Window (WinBox Wrapper)
// ===================================
class TerminalWindow {
constructor(animator) {
this.animator = animator;
this.winbox = null;
this.isMinimized = false;
this.isMaximized = false;
this.isClosed = false;
this.reopenTimeout = null;
this.isMobile = this.detectMobile();
this.container = document.getElementById('terminal-container');
this.reopenBtn = document.getElementById('terminal-reopen');
this.dockElement = null;
this.savedPosition = null;
this.dragEnabled = !this.isMobile;
this.init();
}
detectMobile() {
return window.matchMedia('(max-width: 1024px)').matches ||
'ontouchstart' in window ||
navigator.maxTouchPoints > 0;
}
init() {
this.createWindow();
this.setupReopenButton();
// Update mobile detection on resize
window.addEventListener('resize', () => {
this.isMobile = this.detectMobile();
this.dragEnabled = !this.isMobile;
});
}
createWindow() {
const containerRect = this.container.getBoundingClientRect();
// Create the terminal content
const terminalHTML = `
<div class="terminal-header">
<div class="terminal-buttons">
<span class="terminal-btn red" id="btn-close"></span>
<span class="terminal-btn yellow" id="btn-minimize"></span>
<span class="terminal-btn green" id="btn-maximize"></span>
</div>
<div class="terminal-title">chetech-agent</div>
</div>
<div class="terminal-body">
<div class="terminal-content">
<div class="terminal-line">
<span class="prompt">$</span>
<span class="command" id="terminal-command"></span>
<span class="cursor" id="cursor">|</span>
</div>
<div class="terminal-output" id="terminal-output"></div>
</div>
</div>
`;
// Calculate position
const width = Math.min(540, window.innerWidth - 40);
const height = 380;
// For desktop, position relative to container
// For mobile, center in container
let x, y;
if (this.isMobile) {
x = 'center';
y = containerRect.top + window.scrollY;
} else {
x = containerRect.left + (containerRect.width - width) / 2;
y = containerRect.top + window.scrollY + 20;
}
this.winbox = new WinBox({
title: '',
html: terminalHTML,
width: width,
height: height,
x: x,
y: y,
top: 0,
bottom: 0,
left: 0,
right: 0,
class: ['no-animation', 'no-header'],
background: 'transparent',
border: 0,
header: 0, // Hide default header
move: false, // We handle move ourselves via custom drag handler
resize: !this.isMobile, // Enable resize only on desktop
maximize: false,
minimize: false,
close: false
});
// Make terminal header the drag handle (always set up, but respects dragEnabled)
this.setupDragHandler();
// Remove no-animation class after initial render
setTimeout(() => {
if (this.winbox && this.winbox.dom) {
this.winbox.dom.classList.remove('no-animation');
// Add float animation
if (!this.isMobile) {
this.winbox.dom.style.animation = 'terminalFloat 6s ease-in-out infinite';
}
}
}, 100);
// Set up button handlers
this.setupButtons();
// Connect animator to new elements
this.connectAnimator();
// Hide reopen button
this.reopenBtn.style.display = 'none';
this.isClosed = false;
}
setupButtons() {
const closeBtn = this.winbox.body.querySelector('#btn-close');
const minimizeBtn = this.winbox.body.querySelector('#btn-minimize');
const maximizeBtn = this.winbox.body.querySelector('#btn-maximize');
closeBtn.addEventListener('click', (e) => {
e.stopPropagation();
this.close();
});
minimizeBtn.addEventListener('click', (e) => {
e.stopPropagation();
this.minimize();
});
maximizeBtn.addEventListener('click', (e) => {
e.stopPropagation();
this.toggleMaximize();
});
}
connectAnimator() {
const commandEl = this.winbox.body.querySelector('#terminal-command');
const outputEl = this.winbox.body.querySelector('#terminal-output');
const cursorEl = this.winbox.body.querySelector('#cursor');
this.animator.setElements(commandEl, outputEl, cursorEl);
this.animator.resume();
}
setupReopenButton() {
this.reopenBtn.addEventListener('click', () => {
this.reopen();
});
}
setupDragHandler() {
const terminalHeader = this.winbox.body.querySelector('.terminal-header');
if (!terminalHeader) return;
// Get the WinBox DOM element
const winboxEl = this.winbox.body.parentElement;
if (!winboxEl) return;
let isDragging = false;
let startX, startY;
let startLeft, startTop;
const onMouseDown = (e) => {
// Don't drag if clicking on buttons
if (e.target.closest('.terminal-btn')) return;
// Only respond to left mouse button
if (e.button !== 0) return;
// Don't drag on mobile
if (!this.dragEnabled) return;
isDragging = true;
startX = e.clientX;
startY = e.clientY;
// Get current position from the element's style
startLeft = parseInt(winboxEl.style.left, 10) || 0;
startTop = parseInt(winboxEl.style.top, 10) || 0;
// Remove float animation when dragging starts
winboxEl.style.animation = 'none';
// Add dragging class for visual feedback
winboxEl.classList.add('dragging');
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
e.preventDefault();
e.stopPropagation();
};
const onMouseMove = (e) => {
if (!isDragging) return;
const deltaX = e.clientX - startX;
const deltaY = e.clientY - startY;
const newX = startLeft + deltaX;
const newY = startTop + deltaY;
// Directly set CSS position
winboxEl.style.left = newX + 'px';
winboxEl.style.top = newY + 'px';
e.preventDefault();
};
const onMouseUp = (e) => {
if (!isDragging) return;
isDragging = false;
winboxEl.classList.remove('dragging');
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
e.preventDefault();
};
terminalHeader.addEventListener('mousedown', onMouseDown);
}
close() {
if (this.winbox && !this.isClosed) {
this.animator.pause();
this.winbox.hide();
this.isClosed = true;
// Show reopen button
this.reopenBtn.style.display = 'flex';
// Auto-reopen after 8 seconds
this.reopenTimeout = setTimeout(() => {
if (this.isClosed) {
this.reopen();
}
}, 8000);
}
}
minimize() {
if (this.winbox && !this.isMinimized) {
this.animator.pause();
this.winbox.hide();
this.isMinimized = true;
// Create dock element
this.createDock();
}
}
restore() {
if (this.winbox && this.isMinimized) {
this.winbox.show();
this.isMinimized = false;
this.animator.resume();
// Remove dock
this.removeDock();
}
}
toggleMaximize() {
if (!this.winbox) return;
const winboxEl = this.winbox.body.parentElement;
if (!winboxEl) return;
if (this.isMaximized) {
// Restore to original size and position
winboxEl.style.left = this.savedPosition.left;
winboxEl.style.top = this.savedPosition.top;
winboxEl.style.width = this.savedPosition.width;
winboxEl.style.height = this.savedPosition.height;
winboxEl.style.position = 'absolute';
winboxEl.classList.remove('max');
this.isMaximized = false;
} else {
// Save current position and size
this.savedPosition = {
left: winboxEl.style.left,
top: winboxEl.style.top,
width: winboxEl.style.width,
height: winboxEl.style.height
};
// Maximize - use fixed position and account for nav bar
const navHeight = 72; // var(--nav-height)
winboxEl.style.position = 'fixed';
winboxEl.style.left = '0px';
winboxEl.style.top = navHeight + 'px';
winboxEl.style.width = '100vw';
winboxEl.style.height = `calc(100vh - ${navHeight}px)`;
winboxEl.classList.add('max');
this.isMaximized = true;
}
}
reopen() {
if (this.reopenTimeout) {
clearTimeout(this.reopenTimeout);
this.reopenTimeout = null;
}
if (this.winbox) {
// Show the hidden window
this.winbox.show();
this.isClosed = false;
this.reopenBtn.style.display = 'none';
this.animator.resume();
} else {
// Create new window if it was destroyed
this.createWindow();
}
}
createDock() {
this.dockElement = document.createElement('div');
this.dockElement.className = 'terminal-dock';
this.dockElement.innerHTML = `
<button class="terminal-dock-item">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="18" height="18" rx="2"/>
<path d="M3 9h18"/>
</svg>
chetech-agent
</button>
`;
document.body.appendChild(this.dockElement);
this.dockElement.querySelector('button').addEventListener('click', () => {
this.restore();
});
}
removeDock() {
if (this.dockElement) {
this.dockElement.remove();
this.dockElement = null;
}
}
}
// ===================================
// Navigation
// ===================================
function initNavigation() {
const nav = document.getElementById('nav');
const navToggle = document.getElementById('nav-toggle');
const navLinks = document.getElementById('nav-links');
// Scroll effect
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 50) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
lastScroll = currentScroll;
});
// Mobile toggle
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navLinks.classList.toggle('active');
});
// Close mobile nav on link click
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navToggle.classList.remove('active');
navLinks.classList.remove('active');
});
});
}
// ===================================
// Scroll Animations
// ===================================
function initScrollAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Add fade-in class to elements
const animatedElements = document.querySelectorAll(
'.service-card, .timeline-item, .featured-project, .github-profile, .about-content'
);
animatedElements.forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
}
// ===================================
// Smooth Scroll
// ===================================
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// ===================================
// Initialize
// ===================================
function init() {
initNavigation();
initScrollAnimations();
initSmoothScroll();
// Create terminal animator
const animator = new TerminalAnimator();
// Create terminal window with WinBox
const terminalWindow = new TerminalWindow(animator);
// Start terminal animation
animator.start();
}
// Run when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();