|
1 | 1 | import { LoadableScript, type TriggerEvent } from '../Scripts/loader' |
2 | 2 | import { gsap } from 'gsap' |
| 3 | +import { handleScriptError, addScriptBreadcrumb } from '@components/Scripts/errors' |
3 | 4 |
|
4 | 5 | type Timeline = ReturnType<typeof gsap.timeline> |
5 | 6 |
|
@@ -39,15 +40,19 @@ export class HeroLoader extends LoadableScript { |
39 | 40 | } |
40 | 41 |
|
41 | 42 | private startAnimation() { |
42 | | - if (document.getElementById('heroAnimation') == undefined) return |
| 43 | + const context = { scriptName: HeroLoader.scriptName, operation: 'startAnimation' } |
| 44 | + addScriptBreadcrumb(context) |
43 | 45 |
|
44 | | - if (this.timeline) { |
45 | | - return |
46 | | - } |
| 46 | + try { |
| 47 | + if (document.getElementById('heroAnimation') == undefined) return |
47 | 48 |
|
48 | | - gsap.set('.monitorBottom', { |
49 | | - transformOrigin: '50% 100%', |
50 | | - }) |
| 49 | + if (this.timeline) { |
| 50 | + return |
| 51 | + } |
| 52 | + |
| 53 | + gsap.set('.monitorBottom', { |
| 54 | + transformOrigin: '50% 100%', |
| 55 | + }) |
51 | 56 |
|
52 | 57 | gsap.set(['.monitorStand', '.laptopBase', '.tabletScreen'], { |
53 | 58 | transformOrigin: '50% 0%', |
@@ -385,30 +390,63 @@ export class HeroLoader extends LoadableScript { |
385 | 390 | delay: 2, |
386 | 391 | ease: 'back.in(2)', |
387 | 392 | }) |
| 393 | + } catch (error) { |
| 394 | + // Animation is optional enhancement - handle gracefully |
| 395 | + handleScriptError(error, context) |
| 396 | + } |
388 | 397 | } |
389 | 398 |
|
390 | 399 | static override init() { |
391 | | - if (!HeroLoader.instance) { |
392 | | - HeroLoader.instance = new HeroLoader() |
| 400 | + const context = { scriptName: HeroLoader.scriptName, operation: 'init' } |
| 401 | + addScriptBreadcrumb(context) |
| 402 | + |
| 403 | + try { |
| 404 | + if (!HeroLoader.instance) { |
| 405 | + HeroLoader.instance = new HeroLoader() |
| 406 | + } |
| 407 | + HeroLoader.instance.startAnimation() |
| 408 | + } catch (error) { |
| 409 | + // Animation is optional - page still works without it |
| 410 | + handleScriptError(error, context) |
393 | 411 | } |
394 | | - HeroLoader.instance.startAnimation() |
395 | 412 | } |
396 | 413 |
|
397 | 414 | static override pause() { |
398 | | - if (HeroLoader.instance?.timeline) { |
399 | | - HeroLoader.instance.timeline.pause() |
| 415 | + const context = { scriptName: HeroLoader.scriptName, operation: 'pause' } |
| 416 | + addScriptBreadcrumb(context) |
| 417 | + |
| 418 | + try { |
| 419 | + if (HeroLoader.instance?.timeline) { |
| 420 | + HeroLoader.instance.timeline.pause() |
| 421 | + } |
| 422 | + } catch (error) { |
| 423 | + handleScriptError(error, context) |
400 | 424 | } |
401 | 425 | } |
402 | 426 |
|
403 | 427 | static override resume() { |
404 | | - if (HeroLoader.instance?.timeline) { |
405 | | - HeroLoader.instance.timeline.play() |
| 428 | + const context = { scriptName: HeroLoader.scriptName, operation: 'resume' } |
| 429 | + addScriptBreadcrumb(context) |
| 430 | + |
| 431 | + try { |
| 432 | + if (HeroLoader.instance?.timeline) { |
| 433 | + HeroLoader.instance.timeline.play() |
| 434 | + } |
| 435 | + } catch (error) { |
| 436 | + handleScriptError(error, context) |
406 | 437 | } |
407 | 438 | } |
408 | 439 |
|
409 | 440 | static override reset() { |
410 | | - if (HeroLoader.instance?.timeline) { |
411 | | - HeroLoader.instance.timeline.restart() |
| 441 | + const context = { scriptName: HeroLoader.scriptName, operation: 'reset' } |
| 442 | + addScriptBreadcrumb(context) |
| 443 | + |
| 444 | + try { |
| 445 | + if (HeroLoader.instance?.timeline) { |
| 446 | + HeroLoader.instance.timeline.restart() |
| 447 | + } |
| 448 | + } catch (error) { |
| 449 | + handleScriptError(error, context) |
412 | 450 | } |
413 | 451 | } |
414 | 452 | } |
0 commit comments