API Documentation

Basic Usage

<screen-saver timeout="180" effect="bounce3d"> Your Text Here </screen-saver>

Attributes

Attribute Type Default Description
timeout number 180 Idle delay in seconds before activation
effect string "bounce3d" Effect name: "bounce3d", "matrix", or "ascii-glitch"
speed number 1 Animation speed multiplier (0.5 to 3)
background string - Background color or image URL

Properties

Property Type Description
isActive boolean (readonly) Whether the screen saver is currently active
timeout number Get/set the idle timeout in seconds
effect string Get/set the current effect name
speed number Get/set the animation speed multiplier
background string | null Get/set the background color or image

Methods

activate()

Programmatically activate the screen saver.

const el = document.querySelector('screen-saver'); el.activate();

deactivate()

Programmatically deactivate the screen saver.

el.deactivate();

ScreenSaver.registerEffect(name, effectClass)

Register a custom effect.

import { ScreenSaver, Effect } from 'screen-saver'; class MyEffect extends Effect { start() { // Create your effect in this.container // Use this.text for the slot content // Use this.speed for animation speed // Check this.reducedMotion for accessibility } stop() { // Clean up animations super.stop(); // Cancels requestAnimationFrame } destroy() { // Full cleanup super.destroy(); // Calls stop() and clears container } } ScreenSaver.registerEffect('my-effect', MyEffect);

Events

screensaver-activate

Fired when the screen saver activates.

el.addEventListener('screensaver-activate', () => { console.log('Screen saver started'); });

screensaver-deactivate

Fired when the screen saver dismisses. Includes duration in milliseconds.

el.addEventListener('screensaver-deactivate', (e) => { console.log(`Active for ${e.detail.duration}ms`); });

CSS Custom Properties

Property Default Description
--screen-saver-bg rgba(0, 0, 0, 0.95) Overlay background color
--screen-saver-text-color #00ff00 Primary text color
--screen-saver-extrude-color #003300 3D extrusion color (bounce3d)
--screen-saver-font-family 'Arial Black', sans-serif Font family for displayed text
--screen-saver-font-size 4rem Font size for displayed text
--screen-saver-z-index 999999 Z-index of the overlay

Accessibility

Reduced Motion

The component automatically detects prefers-reduced-motion: reduce and displays static centered text without animation.

ARIA

The overlay has role="dialog" and appropriate aria-label and aria-hidden attributes that update with the component state.

Keyboard Dismissal

The screen saver can be dismissed by pressing any key.

TypeScript

import { ScreenSaver, Effect } from 'screen-saver'; // Element is typed const el = document.querySelector('screen-saver') as ScreenSaver; // Properties are typed el.timeout = 300; el.effect = 'matrix'; // Events are typed el.addEventListener('screensaver-deactivate', (e: CustomEvent<{ duration: number }>) => { console.log(e.detail.duration); });

Built-in Effects

bounce3d

Classic DVD-logo style bouncing text with 3D depth effect.

matrix

Digital rain effect inspired by The Matrix.

ascii-glitch

Cyberpunk-style glitch effect.