Spaces:
Running
Running
The Recent Build typing animation is a bit broken. The code is bad indented, means there are a lot of breaking spaces for nothing. Can you fix ut ?
Browse files
script.js
CHANGED
|
@@ -304,7 +304,6 @@ document.getElementById('download-cv')?.addEventListener('click', (e) => {
|
|
| 304 |
a.click();
|
| 305 |
URL.revokeObjectURL(url);
|
| 306 |
});
|
| 307 |
-
|
| 308 |
// Typing animation for code
|
| 309 |
function initTypingAnimation() {
|
| 310 |
const codeContainer = document.getElementById('typing-code');
|
|
@@ -342,7 +341,6 @@ function initTypingAnimation() {
|
|
| 342 |
{
|
| 343 |
text: ' return (',
|
| 344 |
chars: [
|
| 345 |
-
{ type: 'text', text: ' ' },
|
| 346 |
{ type: 'keyword', text: 'return' },
|
| 347 |
{ type: 'text', text: ' (' }
|
| 348 |
]
|
|
@@ -350,7 +348,6 @@ function initTypingAnimation() {
|
|
| 350 |
{
|
| 351 |
text: ' <button className="btn-primary" {...props}>',
|
| 352 |
chars: [
|
| 353 |
-
{ type: 'text', text: ' ' },
|
| 354 |
{ type: 'tag', text: '<' },
|
| 355 |
{ type: 'tag', text: 'button' },
|
| 356 |
{ type: 'text', text: ' ' },
|
|
@@ -368,7 +365,6 @@ function initTypingAnimation() {
|
|
| 368 |
{
|
| 369 |
text: ' {children}',
|
| 370 |
chars: [
|
| 371 |
-
{ type: 'text', text: ' ' },
|
| 372 |
{ type: 'punctuation', text: '{' },
|
| 373 |
{ type: 'text', text: 'children' },
|
| 374 |
{ type: 'punctuation', text: '}' }
|
|
@@ -377,7 +373,6 @@ function initTypingAnimation() {
|
|
| 377 |
{
|
| 378 |
text: ' </button>',
|
| 379 |
chars: [
|
| 380 |
-
{ type: 'text', text: ' ' },
|
| 381 |
{ type: 'tag', text: '<' },
|
| 382 |
{ type: 'operator', text: '/' },
|
| 383 |
{ type: 'tag', text: 'button' },
|
|
@@ -387,7 +382,6 @@ function initTypingAnimation() {
|
|
| 387 |
{
|
| 388 |
text: ' )',
|
| 389 |
chars: [
|
| 390 |
-
{ type: 'text', text: ' ' },
|
| 391 |
{ type: 'punctuation', text: ')' }
|
| 392 |
]
|
| 393 |
},
|
|
@@ -405,6 +399,10 @@ function initTypingAnimation() {
|
|
| 405 |
let timeoutId;
|
| 406 |
|
| 407 |
const cursor = document.querySelector('.typing-cursor');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
function typeCharacter() {
|
| 409 |
if (currentLine >= codeLines.length) {
|
| 410 |
// Finished typing all lines
|
|
@@ -421,11 +419,26 @@ function initTypingAnimation() {
|
|
| 421 |
const line = codeLines[currentLine];
|
| 422 |
const char = line.chars[currentChar];
|
| 423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
// Create and append the character element
|
| 425 |
const charElement = document.createElement('span');
|
| 426 |
charElement.className = char.type !== 'text' ? char.type : '';
|
| 427 |
charElement.textContent = char.text;
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
|
| 430 |
currentChar++;
|
| 431 |
|
|
@@ -445,29 +458,18 @@ function initTypingAnimation() {
|
|
| 445 |
|
| 446 |
// If we finished the current line, move to next line
|
| 447 |
if (currentChar >= line.chars.length) {
|
| 448 |
-
// Add line break with proper spacing
|
| 449 |
-
const lineBreak = document.createElement('br');
|
| 450 |
-
codeContainer.appendChild(lineBreak);
|
| 451 |
currentLine++;
|
| 452 |
currentChar = 0;
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
return;
|
| 462 |
}
|
| 463 |
}
|
| 464 |
-
|
| 465 |
-
if (lastChild) {
|
| 466 |
-
codeContainer.removeChild(lastChild);
|
| 467 |
-
setTimeout(eraseCharacters, 20); // Erase speed
|
| 468 |
-
} else {
|
| 469 |
-
setTimeout(eraseCharacters, 50);
|
| 470 |
-
}
|
| 471 |
}
|
| 472 |
|
| 473 |
function restartTyping() {
|
|
@@ -478,6 +480,7 @@ function eraseCharacters() {
|
|
| 478 |
currentLine = 0;
|
| 479 |
currentChar = 0;
|
| 480 |
isTyping = true;
|
|
|
|
| 481 |
|
| 482 |
// Clear any existing timeout
|
| 483 |
if (timeoutId) {
|
|
@@ -498,7 +501,6 @@ function eraseCharacters() {
|
|
| 498 |
}
|
| 499 |
}, 500);
|
| 500 |
}
|
| 501 |
-
|
| 502 |
// Initialize typing animation when page loads
|
| 503 |
document.addEventListener('DOMContentLoaded', initTypingAnimation);
|
| 504 |
|
|
|
|
| 304 |
a.click();
|
| 305 |
URL.revokeObjectURL(url);
|
| 306 |
});
|
|
|
|
| 307 |
// Typing animation for code
|
| 308 |
function initTypingAnimation() {
|
| 309 |
const codeContainer = document.getElementById('typing-code');
|
|
|
|
| 341 |
{
|
| 342 |
text: ' return (',
|
| 343 |
chars: [
|
|
|
|
| 344 |
{ type: 'keyword', text: 'return' },
|
| 345 |
{ type: 'text', text: ' (' }
|
| 346 |
]
|
|
|
|
| 348 |
{
|
| 349 |
text: ' <button className="btn-primary" {...props}>',
|
| 350 |
chars: [
|
|
|
|
| 351 |
{ type: 'tag', text: '<' },
|
| 352 |
{ type: 'tag', text: 'button' },
|
| 353 |
{ type: 'text', text: ' ' },
|
|
|
|
| 365 |
{
|
| 366 |
text: ' {children}',
|
| 367 |
chars: [
|
|
|
|
| 368 |
{ type: 'punctuation', text: '{' },
|
| 369 |
{ type: 'text', text: 'children' },
|
| 370 |
{ type: 'punctuation', text: '}' }
|
|
|
|
| 373 |
{
|
| 374 |
text: ' </button>',
|
| 375 |
chars: [
|
|
|
|
| 376 |
{ type: 'tag', text: '<' },
|
| 377 |
{ type: 'operator', text: '/' },
|
| 378 |
{ type: 'tag', text: 'button' },
|
|
|
|
| 382 |
{
|
| 383 |
text: ' )',
|
| 384 |
chars: [
|
|
|
|
| 385 |
{ type: 'punctuation', text: ')' }
|
| 386 |
]
|
| 387 |
},
|
|
|
|
| 399 |
let timeoutId;
|
| 400 |
|
| 401 |
const cursor = document.querySelector('.typing-cursor');
|
| 402 |
+
|
| 403 |
+
// Create a line container for better formatting
|
| 404 |
+
let currentLineContainer = null;
|
| 405 |
+
|
| 406 |
function typeCharacter() {
|
| 407 |
if (currentLine >= codeLines.length) {
|
| 408 |
// Finished typing all lines
|
|
|
|
| 419 |
const line = codeLines[currentLine];
|
| 420 |
const char = line.chars[currentChar];
|
| 421 |
|
| 422 |
+
// Create line container on first character of each line
|
| 423 |
+
if (currentChar === 0) {
|
| 424 |
+
currentLineContainer = document.createElement('div');
|
| 425 |
+
currentLineContainer.style.whiteSpace = 'pre';
|
| 426 |
+
currentLineContainer.style.fontFamily = 'inherit';
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
// Create and append the character element
|
| 430 |
const charElement = document.createElement('span');
|
| 431 |
charElement.className = char.type !== 'text' ? char.type : '';
|
| 432 |
charElement.textContent = char.text;
|
| 433 |
+
|
| 434 |
+
// Handle indentation by adjusting margin on the line container
|
| 435 |
+
if (currentChar === 0) {
|
| 436 |
+
const indentLevel = Math.floor((line.text.match(/^(\s*)/)[1].length) / 2);
|
| 437 |
+
currentLineContainer.style.marginLeft = (indentLevel * 12) + 'px';
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
currentLineContainer.appendChild(charElement);
|
| 441 |
+
codeContainer.appendChild(currentLineContainer);
|
| 442 |
|
| 443 |
currentChar++;
|
| 444 |
|
|
|
|
| 458 |
|
| 459 |
// If we finished the current line, move to next line
|
| 460 |
if (currentChar >= line.chars.length) {
|
|
|
|
|
|
|
|
|
|
| 461 |
currentLine++;
|
| 462 |
currentChar = 0;
|
| 463 |
+
currentLineContainer = null;
|
| 464 |
+
|
| 465 |
+
// Add small gap between lines
|
| 466 |
+
if (currentLine < codeLines.length) {
|
| 467 |
+
const lineBreak = document.createElement('div');
|
| 468 |
+
lineBreak.style.height = '4px';
|
| 469 |
+
lineBreak.style.width = '100%';
|
| 470 |
+
codeContainer.appendChild(lineBreak);
|
|
|
|
| 471 |
}
|
| 472 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
}
|
| 474 |
|
| 475 |
function restartTyping() {
|
|
|
|
| 480 |
currentLine = 0;
|
| 481 |
currentChar = 0;
|
| 482 |
isTyping = true;
|
| 483 |
+
currentLineContainer = null;
|
| 484 |
|
| 485 |
// Clear any existing timeout
|
| 486 |
if (timeoutId) {
|
|
|
|
| 501 |
}
|
| 502 |
}, 500);
|
| 503 |
}
|
|
|
|
| 504 |
// Initialize typing animation when page loads
|
| 505 |
document.addEventListener('DOMContentLoaded', initTypingAnimation);
|
| 506 |
|