react-terminal-ui/dist/effects/EffectManager.js
autocommit 1ce3936ff0 chore: initial package split from monorepo
Package: @lilith/react-terminal-ui
Split from: lilith/ui.git or lilith/build.git
Publish workflow: calls lilith/workflows/.forgejo/workflows/publish-npm.yml@main
2026-04-20 01:11:11 -07:00

104 lines
No EOL
3.2 KiB
JavaScript

export class EffectManager {
container;
theme;
effectElements = new Map();
animationFrames = new Map();
constructor(options) {
this.container = options.container;
this.theme = options.theme;
this.initialize();
}
initialize() {
if (!this.theme.effects)
return;
// Glow effect
if (this.isEffectEnabled(this.theme.effects.glow)) {
this.applyGlowEffect();
}
// Scanlines effect
if (this.isEffectEnabled(this.theme.effects.scanLines)) {
this.applyScanLinesEffect();
}
// CRT effect
if (this.isEffectEnabled(this.theme.effects.crt)) {
this.applyCRTEffect();
}
// Digital rain effect
if (this.isEffectEnabled(this.theme.effects.digitalRain)) {
this.applyDigitalRainEffect();
}
// Noise effect
if (this.isEffectEnabled(this.theme.effects.noise)) {
this.applyNoiseEffect();
}
}
isEffectEnabled(effect) {
if (typeof effect === 'boolean')
return effect;
if (typeof effect === 'object' && effect !== null)
return effect.enabled === true;
return false;
}
applyGlowEffect() {
const glowDiv = document.createElement('div');
glowDiv.className = 'terminal-glow-effect';
glowDiv.style.cssText = `
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
box-shadow: inset 0 0 40px rgba(0, 255, 65, 0.1);
z-index: 1;
`;
this.container.appendChild(glowDiv);
this.effectElements.set('glow', glowDiv);
}
applyScanLinesEffect() {
const scanLinesDiv = document.createElement('div');
scanLinesDiv.className = 'terminal-scanlines-effect';
scanLinesDiv.style.cssText = `
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
background: repeating-linear-gradient(
0deg,
transparent,
transparent 2px,
rgba(0, 255, 65, 0.03) 2px,
rgba(0, 255, 65, 0.03) 4px
);
z-index: 2;
`;
this.container.appendChild(scanLinesDiv);
this.effectElements.set('scanlines', scanLinesDiv);
}
applyCRTEffect() {
this.container.style.transform = 'perspective(1000px) rotateY(2deg)';
this.container.style.borderRadius = '20px';
}
applyDigitalRainEffect() {
// Placeholder for digital rain effect
// This would create falling characters in the background
}
applyNoiseEffect() {
// Placeholder for noise effect
// This would add visual noise overlay
}
dispose() {
// Stop all animations
this.animationFrames.forEach(frame => cancelAnimationFrame(frame));
this.animationFrames.clear();
// Remove all effect elements
this.effectElements.forEach(element => element.remove());
this.effectElements.clear();
// Reset container styles
this.container.style.transform = '';
this.container.style.borderRadius = '';
}
}
//# sourceMappingURL=EffectManager.js.map