File size: 10,782 Bytes
540412a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**

 * Terminal Effects Module

 * Handles all the aesthetic terminal animations and effects

 */

class TerminalEffects {
    constructor() {
        this.isGlitching = false;
        this.scanlineInterval = null;
        this.init();
    }

    init() {
        this.createScanlines();
        this.initCursorBlink();
        this.initRandomGlitches();
        this.initTypingEffects();
        this.initMatrixRain();
    }

    // Create CRT scanline effect
    createScanlines() {
        const scanlines = document.createElement('div');
        scanlines.className = 'scanlines';
        scanlines.innerHTML = Array(50).fill().map((_, i) => 
            `<div class="scanline" style="top: ${i * 2}%"></div>`
        ).join('');
        
        const style = document.createElement('style');
        style.textContent = `

            .scanlines {

                position: fixed;

                top: 0;

                left: 0;

                right: 0;

                bottom: 0;

                pointer-events: none;

                z-index: 1000;

                opacity: 0.03;

            }

            

            .scanline {

                position: absolute;

                left: 0;

                right: 0;

                height: 1px;

                background: #39ff14;

                animation: scanline-flicker 0.1s infinite alternate;

            }

            

            @keyframes scanline-flicker {

                0% { opacity: 0.8; }

                100% { opacity: 0.2; }

            }

        `;
        
        document.head.appendChild(style);
        document.body.appendChild(scanlines);
    }

    // Enhanced cursor blinking
    initCursorBlink() {
        const cursors = document.querySelectorAll('.brand-cursor');
        cursors.forEach(cursor => {
            setInterval(() => {
                cursor.style.opacity = cursor.style.opacity === '0' ? '1' : '0';
            }, 500 + Math.random() * 200); // Slight randomness
        });
    }

    // Random glitch effects
    initRandomGlitches() {
        setInterval(() => {
            if (Math.random() < 0.02 && !this.isGlitching) { // 2% chance
                this.triggerGlitch();
            }
        }, 1000);
    }

    triggerGlitch() {
        if (this.isGlitching) return;
        
        this.isGlitching = true;
        const elements = document.querySelectorAll('.terminal-card, .chat-message');
        const randomElement = elements[Math.floor(Math.random() * elements.length)];
        
        if (randomElement) {
            const originalTransform = randomElement.style.transform;
            const glitchIntensity = Math.random() * 5;
            
            // Apply glitch effect
            randomElement.style.filter = `hue-rotate(${Math.random() * 360}deg) saturate(2)`;
            randomElement.style.transform = `translateX(${Math.random() * glitchIntensity - glitchIntensity/2}px) skew(${Math.random() * 2}deg)`;
            
            // Create text shadow glitch
            randomElement.style.textShadow = `

                ${Math.random() * 10 - 5}px 0 #ff0000,

                ${Math.random() * 10 - 5}px 0 #00ff00,

                ${Math.random() * 10 - 5}px 0 #0000ff

            `;
            
            setTimeout(() => {
                randomElement.style.filter = '';
                randomElement.style.transform = originalTransform;
                randomElement.style.textShadow = '';
                this.isGlitching = false;
            }, 50 + Math.random() * 100);
        } else {
            this.isGlitching = false;
        }
    }

    // Typing animation for new elements
    typeWriter(element, text, speed = 50, callback = null) {
        let i = 0;
        element.textContent = '';
        
        const timer = setInterval(() => {
            if (i < text.length) {
                element.textContent += text.charAt(i);
                i++;
                
                // Add random typing delays
                if (Math.random() < 0.1) {
                    clearInterval(timer);
                    setTimeout(() => {
                        this.typeWriter(element, text.substring(i), speed, callback);
                    }, speed * 2);
                    return;
                }
            } else {
                clearInterval(timer);
                if (callback) callback();
            }
        }, speed);
    }

    initTypingEffects() {
        // Apply to elements that should have typing effect
        const typeElements = document.querySelectorAll('.typewriter-effect');
        typeElements.forEach(element => {
            const text = element.textContent;
            this.typeWriter(element, text, 30);
        });
    }

    // Matrix-style rain effect (subtle)
    initMatrixRain() {
        const canvas = document.createElement('canvas');
        canvas.style.position = 'fixed';
        canvas.style.top = '0';
        canvas.style.left = '0';
        canvas.style.width = '100%';
        canvas.style.height = '100%';
        canvas.style.pointerEvents = 'none';
        canvas.style.zIndex = '-2';
        canvas.style.opacity = '0.03';
        
        const ctx = canvas.getContext('2d');
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        
        const matrix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789@#$%^&*()*&^%+-/~{[|`]}";
        const matrixArray = matrix.split("");
        
        const fontSize = 10;
        const columns = canvas.width / fontSize;
        const drops = [];
        
        for (let x = 0; x < columns; x++) {
            drops[x] = 1;
        }
        
        function draw() {
            ctx.fillStyle = 'rgba(13, 17, 23, 0.04)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            
            ctx.fillStyle = '#39ff14';
            ctx.font = fontSize + 'px monospace';
            
            for (let i = 0; i < drops.length; i++) {
                const text = matrixArray[Math.floor(Math.random() * matrixArray.length)];
                ctx.fillText(text, i * fontSize, drops[i] * fontSize);
                
                if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {
                    drops[i] = 0;
                }
                drops[i]++;
            }
        }
        
        document.body.appendChild(canvas);
        setInterval(draw, 150);
        
        // Resize canvas on window resize
        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
        });
    }

    // Power-on effect for new elements
    powerOnEffect(element) {
        element.style.opacity = '0';
        element.style.transform = 'scale(0.8) rotateX(20deg)';
        element.style.filter = 'brightness(0)';
        
        setTimeout(() => {
            element.style.transition = 'all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275)';
            element.style.opacity = '1';
            element.style.transform = 'scale(1) rotateX(0deg)';
            element.style.filter = 'brightness(1)';
            
            // Add a brief glow effect
            element.style.boxShadow = '0 0 20px var(--terminal-green-glow)';
            setTimeout(() => {
                element.style.boxShadow = '';
            }, 500);
        }, 100);
    }

    // Boot sequence effect
    bootSequence(container, messages, onComplete) {
        let messageIndex = 0;
        const bootContainer = document.createElement('div');
        bootContainer.className = 'boot-sequence';
        bootContainer.innerHTML = `

            <div class="terminal-window">

                <div class="terminal-header">

                    <div class="terminal-dots">

                        <div class="terminal-dot red"></div>

                        <div class="terminal-dot yellow"></div>

                        <div class="terminal-dot green"></div>

                    </div>

                    <h6 class="terminal-title">system_boot.log</h6>

                </div>

                <div class="boot-content bg-dark p-3" style="font-family: var(--terminal-font); min-height: 200px;">

                    <div class="boot-messages"></div>

                </div>

            </div>

        `;
        
        container.appendChild(bootContainer);
        const messagesContainer = bootContainer.querySelector('.boot-messages');
        
        function addMessage() {
            if (messageIndex < messages.length) {
                const messageDiv = document.createElement('div');
                messageDiv.className = 'text-terminal-green';
                messageDiv.innerHTML = `<span class="text-muted">></span> ${messages[messageIndex]}`;
                messagesContainer.appendChild(messageDiv);
                
                // Scroll to bottom
                messagesContainer.scrollTop = messagesContainer.scrollHeight;
                
                messageIndex++;
                setTimeout(addMessage, 300 + Math.random() * 200);
            } else {
                setTimeout(() => {
                    container.removeChild(bootContainer);
                    if (onComplete) onComplete();
                }, 1000);
            }
        }
        
        setTimeout(addMessage, 500);
    }

    // Network activity indicator
    showNetworkActivity() {
        const indicator = document.querySelector('.status-indicator');
        if (indicator) {
            indicator.style.background = '#ffbd2e';
            indicator.style.animation = 'pulse-glow 0.3s infinite';
            
            setTimeout(() => {
                indicator.style.background = 'var(--terminal-green)';
                indicator.style.animation = 'pulse-glow 2s infinite';
            }, 1000);
        }
    }

    // Error flash effect
    errorFlash() {
        document.body.style.backgroundColor = '#ff5f5610';
        setTimeout(() => {
            document.body.style.backgroundColor = '';
        }, 150);
    }

    // Success flash effect
    successFlash() {
        document.body.style.backgroundColor = '#39ff1410';
        setTimeout(() => {
            document.body.style.backgroundColor = '';
        }, 150);
    }
}

// Initialize terminal effects when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
    window.terminalEffects = new TerminalEffects();
});

// Expose for use in other modules
window.TerminalEffects = TerminalEffects;