-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
477 lines (435 loc) · 16 KB
/
Copy pathexample.html
File metadata and controls
477 lines (435 loc) · 16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glass Terminal Demo - All-in-One</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #121212, #1e272e);
font-family: Arial, sans-serif;
color: #eee;
padding: 20px;
}
h1 {
margin-bottom: 30px;
}
.controls {
margin-top: 30px;
display: flex;
gap: 15px;
flex-wrap: wrap;
justify-content: center;
}
button {
background: rgba(70, 70, 70, 0.4);
color: #fff;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 5px;
padding: 8px 16px;
cursor: pointer;
backdrop-filter: blur(5px);
transition: all 0.3s;
}
button:hover {
background: rgba(100, 100, 100, 0.6);
}
#terminal-container {
margin: 40px 0;
}
</style>
</head>
<body>
<h1>Glass Terminal Component Demo</h1>
<div id="terminal-container"></div>
<div class="controls">
<button id="start-btn">Start</button>
<button id="stop-btn">Stop</button>
<button id="reset-btn">Reset</button>
<button id="code-mode-btn">Code Mode</button>
<button id="matrix-mode-btn">Matrix Mode</button>
</div>
<!-- Define the component class directly in this page -->
<script>
/**
* GlassTerminal - A customizable vintage terminal component with glass effects
*
* @class
*/
class GlassTerminal {
/**
* Create a new GlassTerminal instance
*
* @param {Object} options - Configuration options
* @param {string} options.containerId - ID of the container element where the terminal will be mounted
* @param {Array<string>} [options.lines=[]] - Initial lines to display in the terminal
* @param {string} [options.terminalColor='#33ff33'] - Color of the terminal text
* @param {number} [options.width=500] - Width of the component in pixels
* @param {number} [options.height=500] - Height of the component in pixels
* @param {number} [options.fontSize=11] - Font size in pixels
* @param {boolean} [options.autoRestart=true] - Whether to restart typing after completion
*/
constructor(options) {
this.options = Object.assign({
containerId: 'glass-terminal-container',
lines: [
'> initializing system...',
'> loading kernel modules...',
'> mounting virtual filesystem...',
'> starting session daemon...',
'> connected to main server',
'> ',
'> function analyzeData(input) {',
' const result = [];',
' for (let i = 0; i < input.length; i++) {',
' if (input[i] > threshold) {',
' result.push(input[i] * 1.5);',
' } else {',
' result.push(input[i] / 2);',
' }',
' }',
' return result;',
'}',
'> ',
'> const data = [12, 45, 67, 8, 23, 56, 99];',
'> const threshold = 30;',
'> analyzing data...',
'> processing blocks: ████████░░ 80%',
'> results = analyzeData(data);',
'> console.log(results);',
'> [6, 67.5, 100.5, 4, 11.5, 84, 148.5]',
'> ',
'> initiating quantum encrypt sequence...',
'> generating prime factors...',
'> loading cryptographic modules...'
],
terminalColor: '#33ff33',
width: 500,
height: 500,
fontSize: 11,
autoRestart: true
}, options);
this.lineIndex = 0;
this.charIndex = 0;
this.container = null;
this.outputElement = null;
this.isRunning = false;
}
/**
* Generate the CSS styles for the component
*
* @returns {string} CSS styles
* @private
*/
_generateStyles() {
return `
.glass-container {
position: relative;
width: ${this.options.width}px;
height: ${this.options.height}px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 15px;
background: rgba(30, 30, 30, 0.2);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(100, 100, 100, 0.2);
padding: 20px;
}
.glass-circle {
position: relative;
width: ${this.options.width * 0.76}px;
height: ${this.options.height * 0.76}px;
border-radius: 50%;
background: rgba(0, 0, 0, 0.3);
overflow: hidden;
box-shadow:
inset 0 0 50px rgba(255, 255, 255, 0.15),
0 0 20px rgba(0, 0, 0, 0.3);
display: flex;
justify-content: center;
align-items: center;
}
.glass-reflection {
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
background: linear-gradient(
135deg,
rgba(255, 255, 255, 0.1) 0%,
rgba(255, 255, 255, 0.05) 40%,
rgba(255, 255, 255, 0) 60%
);
transform: rotate(-20deg);
pointer-events: none;
}
.terminal {
width: ${this.options.width * 0.68}px;
height: ${this.options.height * 0.68}px;
background: #000;
border-radius: 50%;
padding: 20px;
box-sizing: border-box;
overflow: hidden;
font-size: ${this.options.fontSize}px;
position: relative;
}
.terminal-content {
height: 100%;
overflow: hidden;
color: ${this.options.terminalColor};
text-shadow: 0 0 5px rgba(51, 255, 51, 0.7);
}
.terminal-content pre {
margin: 0;
white-space: pre-wrap;
}
.cursor {
display: inline-block;
width: ${this.options.fontSize * 0.5}px;
height: ${this.options.fontSize * 1.1}px;
background-color: ${this.options.terminalColor};
animation: blink 1s infinite;
vertical-align: bottom;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
.scan-line {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 4px;
background: rgba(51, 255, 51, 0.1);
animation: scan 6s linear infinite;
z-index: 2;
}
@keyframes scan {
0% { top: 0; }
100% { top: 100%; }
}
.terminal-glow {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
box-shadow: inset 0 0 20px rgba(51, 255, 51, 0.2);
pointer-events: none;
z-index: 3;
}
.vintage-effect {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background:
linear-gradient(
rgba(51, 255, 51, 0.02) 50%,
rgba(0, 0, 0, 0.02) 50%
);
background-size: 100% 4px;
z-index: 1;
pointer-events: none;
opacity: 0.3;
border-radius: 50%;
}
`;
}
/**
* Generate the HTML structure for the component
*
* @returns {string} HTML markup
* @private
*/
_generateHTML() {
return `
<div class="glass-container">
<div class="glass-circle">
<div class="glass-reflection"></div>
<div class="terminal">
<div class="terminal-content">
<pre id="${this.options.containerId}-output"></pre>
<span class="cursor"></span>
</div>
<div class="scan-line"></div>
<div class="terminal-glow"></div>
<div class="vintage-effect"></div>
</div>
</div>
</div>
`;
}
/**
* Type the next character in the terminal
*
* @private
*/
_typeNextChar() {
if (!this.isRunning) return;
if (this.lineIndex < this.options.lines.length) {
const currentLine = this.options.lines[this.lineIndex];
if (this.charIndex < currentLine.length) {
this.outputElement.textContent += currentLine.charAt(this.charIndex);
this.charIndex++;
setTimeout(() => this._typeNextChar(), Math.random() * 50 + 10);
} else {
this.outputElement.textContent += '\n';
this.lineIndex++;
this.charIndex = 0;
setTimeout(() => this._typeNextChar(), Math.random() * 300 + 100);
}
} else if (this.options.autoRestart) {
setTimeout(() => {
this.reset();
this._typeNextChar();
}, 3000);
}
}
/**
* Mount the component to the DOM
*/
mount() {
// Find the container element
this.container = document.getElementById(this.options.containerId);
if (!this.container) {
console.error(`Container element with ID '${this.options.containerId}' not found`);
return;
}
// Create a style element
const styleElement = document.createElement('style');
styleElement.textContent = this._generateStyles();
document.head.appendChild(styleElement);
// Set up the HTML structure
this.container.innerHTML = this._generateHTML();
// Get the output element
this.outputElement = document.getElementById(`${this.options.containerId}-output`);
}
/**
* Start the terminal animation
*/
start() {
if (!this.outputElement) {
console.error('Component must be mounted before starting');
return;
}
this.isRunning = true;
this._typeNextChar();
}
/**
* Stop the terminal animation
*/
stop() {
this.isRunning = false;
}
/**
* Reset the terminal to its initial state
*/
reset() {
if (this.outputElement) {
this.outputElement.textContent = '';
this.lineIndex = 0;
this.charIndex = 0;
}
}
/**
* Update the terminal lines
*
* @param {Array<string>} lines - New lines to display
*/
updateLines(lines) {
this.options.lines = lines;
this.reset();
if (this.isRunning) {
this._typeNextChar();
}
}
}
</script>
<!-- Initialize the terminal -->
<script>
// Wait for DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function() {
// Initialize the component
const terminal = new GlassTerminal({
containerId: 'terminal-container'
});
// Mount the component to the DOM
terminal.mount();
// Button event listeners
document.getElementById('start-btn').addEventListener('click', () => {
terminal.start();
});
document.getElementById('stop-btn').addEventListener('click', () => {
terminal.stop();
});
document.getElementById('reset-btn').addEventListener('click', () => {
terminal.reset();
});
document.getElementById('code-mode-btn').addEventListener('click', () => {
terminal.updateLines([
'> initializing system...',
'> loading kernel modules...',
'> mounting virtual filesystem...',
'> starting session daemon...',
'> connected to main server',
'> ',
'> function analyzeData(input) {',
' const result = [];',
' for (let i = 0; i < input.length; i++) {',
' if (input[i] > threshold) {',
' result.push(input[i] * 1.5);',
' } else {',
' result.push(input[i] / 2);',
' }',
' }',
' return result;',
'}',
'> ',
'> const data = [12, 45, 67, 8, 23, 56, 99];',
'> const threshold = 30;',
'> analyzing data...',
'> processing blocks: ████████░░ 80%',
'> results = analyzeData(data);',
'> console.log(results);',
'> [6, 67.5, 100.5, 4, 11.5, 84, 148.5]',
'> ',
'> initiating quantum encrypt sequence...',
'> generating prime factors...',
'> loading cryptographic modules...'
]);
terminal.start();
});
document.getElementById('matrix-mode-btn').addEventListener('click', () => {
const matrixLines = [];
for (let i = 0; i < 30; i++) {
let line = '> ';
for (let j = 0; j < Math.floor(Math.random() * 50) + 10; j++) {
// Random Matrix-like characters
const chars = '01アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン';
line += chars[Math.floor(Math.random() * chars.length)];
}
matrixLines.push(line);
}
terminal.updateLines(matrixLines);
terminal.start();
});
// Start the animation
terminal.start();
});
</script>
</body>
</html>