### Install PowerGlitch with npm or yarn Source: https://context7.com/7ph/powerglitch/llms.txt Install the PowerGlitch library using your preferred package manager. ```bash npm install powerglitch # or yarn add powerglitch ``` -------------------------------- ### Install PowerGlitch with npm or yarn Source: https://github.com/7ph/powerglitch/blob/master/README.md Install PowerGlitch using your preferred package manager. This is the recommended way to add the library to your project. ```bash npm i --save powerglitch ``` ```bash yarn add powerglitch ``` -------------------------------- ### Retrieve Default PowerGlitch Options Source: https://context7.com/7ph/powerglitch/llms.txt Use `PowerGlitch.getDefaultOptions()` to get the default configuration object for a given play mode. This is useful for inspecting defaults or creating a base configuration to extend. ```javascript import { PowerGlitch } from 'powerglitch'; // Get defaults for the 'always' play mode (default) const defaults = PowerGlitch.getDefaultOptions(); console.log(defaults); // { // playMode: 'always', // optimizeSeo: true, // createContainers: true, // hideOverflow: false, // timing: { duration: 2000, iterations: Infinity }, // glitchTimeSpan: { start: 0.5, end: 0.7 }, // shake: { velocity: 15, amplitudeX: 0.2, amplitudeY: 0.2 }, // slice: { count: 6, velocity: 15, minHeight: 0.02, maxHeight: 0.15, hueRotate: true, cssFilters: '' }, // pulse: false // } // Get defaults tuned for click mode (shorter, one-shot animation) const clickDefaults = PowerGlitch.getDefaultOptions('click'); console.log(clickDefaults.timing); // { duration: 250, iterations: 1 } console.log(clickDefaults.slice.count); // 15 — more slices for a punchier one-shot effect ``` -------------------------------- ### Play Modes - `playMode` Option Source: https://context7.com/7ph/powerglitch/llms.txt Configures the interaction trigger for the glitch animation, determining when it starts and stops. ```APIDOC ## Play Modes — `playMode` option ### Description Selects the interaction trigger that controls when the glitch animation plays. The default is `'always'`. ### Options - `always`: The animation loops indefinitely. - `hover`: The animation starts on mouseenter and stops on mouseleave. - `click`: The animation plays one burst on each click. - `manual`: The animation never starts automatically; it requires explicit calls to `startGlitch()`. ### Usage Examples ```javascript import { PowerGlitch } from 'powerglitch'; // Always playing (default) PowerGlitch.glitch('.logo', { playMode: 'always' }); // Hover PowerGlitch.glitch('.logo', { playMode: 'hover' }); // Click PowerGlitch.glitch('.logo', { playMode: 'click' }); // Manual control const { startGlitch, stopGlitch } = PowerGlitch.glitch('.logo', { playMode: 'manual', }); document.querySelector('#trigger').addEventListener('click', () => { stopGlitch(); // cancel any in-progress animation startGlitch(); // start a fresh burst }); ``` ``` -------------------------------- ### Generate Raw Animation Layer Definitions Source: https://context7.com/7ph/powerglitch/llms.txt Use `PowerGlitch.generateLayers()` to produce raw `LayerDefinition` objects for advanced integration where you manage DOM setup and animation playback. This function takes a resolved options object. ```javascript import { PowerGlitch, mergeOptions } from 'powerglitch'; // Build a fully resolved options object and inspect the generated layers const options = mergeOptions( PowerGlitch.getDefaultOptions('always'), { timing: { duration: 1000, iterations: Infinity }, slice: { count: 4, hueRotate: false, cssFilters: 'blur(3px) saturate(2)', }, pulse: { scale: 1.5 }, } ); const layers = PowerGlitch.generateLayers(options); // layers[0] — base shake layer (LayerDefinition) // layers[1] — pulse layer (if pulse != false) // layers[2…] — slice layers (one per options.slice.count) layers.forEach((layer, i) => { console.log(`Layer ${i}: ${layer.steps.length} keyframes`); // e.g. "Layer 0: 16 keyframes" }); // Apply layers to your own pre-built DOM structure (createContainers: false) // HTML:
```
--------------------------------
### PowerGlitch Options
Source: https://github.com/7ph/powerglitch/blob/master/docs/api-docs/types/PowerGlitchOptions.html
Configuration options for the PowerGlitch effect.
```APIDOC
## PowerGlitch Options
### Description
These options allow for fine-grained control over the PowerGlitch animation.
### Properties
* **optimizeSeo**: `boolean` - Whether to avoid running the glitch effect on crawlers for SEO optimization.
* **html**: `string` (Optional) - HTML content to glitch. If not provided, the elements themselves will be used. If provided, all elements should have an `innerHTML` property.
* **createContainers**: `boolean` - Whether to create the necessary containers for the glitch animation (defaults to true). If false, it's assumed the containers are handled externally.
* **playMode**: `PlayModes` - Defines the default behavior for playing the glitch animation.
* **hideOverflow**: `boolean` - Whether to hide the glitch animation when it extends beyond the bounding rectangle.
* **timing**: `object` - Specifies the timing of the animation.
* **duration**: `number` - Duration of the animation loop in milliseconds.
* **iterations**: `number` - Number of times the animation should repeat. Set to `Infinity` for infinite repetition.
* **easing**: `string` (Optional) - Ease animation for all layers. Defaults to a sequential easing.
* **glitchTimeSpan**: `false | { start: number, end: number }` - Specifies if the animation should glitch uniformly or at a given time range. If `false`, it glitches uniformly. If an object with `start` and `end` times is provided, the glitch occurs within that range, peaking in the middle. `end` must be greater than `start`.
* **shake**: `false | { velocity: number, amplitudeX: number, amplitudeY: number }` - Configures whether the base layer should shake and its parameters. Respects `glitchTimeSpan` if set.
* **slice**: `object` - Configures the slice layers, which are the base animation for the glitch effect.
* **count**: `number` - Number of slice layers to generate.
* **velocity**: `number` - Number of steps for each layer per second of animation.
* **minHeight**: `number` - Minimum height percentage for a slice (0 to 1).
* **maxHeight**: `number` - Maximum height percentage for a slice (0 to 1).
* **hueRotate**: `boolean` - Whether hue should rotate for the slice.
* **cssFilters**: `string` - Custom CSS filters to apply to glitch layers. Disables `hueRotate` if set. Respects `glitchTimeSpan` if set.
* **pulse**: `false | { scale: number }` - Adds a pulsing effect to the glitch animation.
```
--------------------------------
### Import PowerGlitch using ES5 require
Source: https://github.com/7ph/powerglitch/blob/master/README.md
Import the PowerGlitch class into your JavaScript file using ES5 require syntax.
```javascript
const PowerGlitch = require('powerglitch').PowerGlitch
```
--------------------------------
### Retrieve Default Options
Source: https://context7.com/7ph/powerglitch/llms.txt
Retrieve the default configuration options for PowerGlitch. This is useful for inspecting defaults or creating a base configuration to extend.
```APIDOC
## `PowerGlitch.getDefaultOptions()` — Retrieve default configuration
Returns the full `PowerGlitchOptions` object pre-tuned for the given play mode. Useful for inspecting defaults or building a base configuration to extend.
```js
import { PowerGlitch } from 'powerglitch';
// Get defaults for the 'always' play mode (default)
const defaults = PowerGlitch.getDefaultOptions();
console.log(defaults);
// {
// playMode: 'always',
// optimizeSeo: true,
// createContainers: true,
// hideOverflow: false,
// timing: { duration: 2000, iterations: Infinity },
// glitchTimeSpan: { start: 0.5, end: 0.7 },
// shake: { velocity: 15, amplitudeX: 0.2, amplitudeY: 0.2 },
// slice: { count: 6, velocity: 15, minHeight: 0.02, maxHeight: 0.15, hueRotate: true, cssFilters: '' },
// pulse: false
// }
// Get defaults tuned for click mode (shorter, one-shot animation)
const clickDefaults = PowerGlitch.getDefaultOptions('click');
console.log(clickDefaults.timing);
// { duration: 250, iterations: 1 }
console.log(clickDefaults.slice.count);
// 15 — more slices for a punchier one-shot effect
```
```
--------------------------------
### Import PowerGlitch using ES6 import
Source: https://github.com/7ph/powerglitch/blob/master/README.md
Import the PowerGlitch class into your JavaScript module using ES6 import syntax.
```javascript
import { PowerGlitch } from 'powerglitch'
```
--------------------------------
### PowerGlitch.getDefaultOptions
Source: https://github.com/7ph/powerglitch/blob/master/docs/api-docs/variables/PowerGlitch.html
Retrieves the default options for creating glitch effects, optimized for visual appeal, with an option to specify the play mode.
```APIDOC
## PowerGlitch.getDefaultOptions
### Description
Get best-looking default options for most elements for a given playMode.
### Method
(playMode?: [PlayModes]): [PowerGlitchOptions]
### Parameters
#### Path Parameters
- **playMode** ([PlayModes]): Optional. The play mode for which to get default options. Defaults to 'always'.
### Returns
[PowerGlitchOptions]
```
--------------------------------
### Include PowerGlitch via CDN
Source: https://context7.com/7ph/powerglitch/llms.txt
Include the PowerGlitch library in your HTML using a script tag from a CDN to expose the global PowerGlitch variable.
```html
```
--------------------------------
### React integration using refs and useEffect
Source: https://context7.com/7ph/powerglitch/llms.txt
Integrate PowerGlitch in React by using a ref to target the element and useEffect to initiate the glitch on component mount. Ensure cleanup by calling stopGlitch on unmount.
```jsx
import { useEffect, useRef } from 'react';
import { PowerGlitch } from 'powerglitch';
export function GlitchTitle() {
const ref = useRef(null);
useEffect(() => {
const { stopGlitch } = PowerGlitch.glitch(ref.current, {
playMode: 'hover',
});
return () => stopGlitch(); // clean up on unmount
}, []);
return Injected content
', }); // Full options example const { containers, startGlitch, stopGlitch } = PowerGlitch.glitch('.glitch', { playMode: 'always', // 'always' | 'hover' | 'click' | 'manual' optimizeSeo: true, // skip animation for known web crawlers createContainers: true, // let PowerGlitch manage the wrapper DOM hideOverflow: true, // clip slices that go outside the element bounds timing: { duration: 2000, // animation loop length in ms iterations: Infinity, // repeat count (Infinity = loop forever) easing: 'ease-in-out', // CSS easing for all layers }, glitchTimeSpan: { start: 0.4, // glitch starts at 40 % of each loop end: 0.7, // glitch ends at 70 % of each loop }, shake: { velocity: 15, // steps per second for the shake layer amplitudeX: 0.2, // max X displacement as fraction of width amplitudeY: 0.2, // max Y displacement as fraction of height }, slice: { count: 6, // number of clipping/translating slice layers velocity: 15, // steps per second for slice layers minHeight: 0.02, // min slice height as fraction of element height maxHeight: 0.15, // max slice height as fraction of element height hueRotate: true, // apply random hue-rotation to each slice cssFilters: '', // custom CSS filter string; overrides hueRotate }, pulse: false, // or { scale: 1.5 } to add a pulsing layer }); // containers: HTMLDivElement[] — the top-level wrappers around each glitched element console.log('Wrapper elements:', containers); // Programmatically pause and resume the animation stopGlitch(); setTimeout(startGlitch, 1000); ``` ``` -------------------------------- ### PowerGlitch Play Modes Source: https://context7.com/7ph/powerglitch/llms.txt Configure the `playMode` option to control when the glitch animation triggers. Options include 'always', 'hover', 'click', and 'manual' for programmatic control. ```javascript import { PowerGlitch } from 'powerglitch'; // Always playing (default) — loops indefinitely PowerGlitch.glitch('.logo', { playMode: 'always' }); // Hover — starts on mouseenter, stops on mouseleave PowerGlitch.glitch('.logo', { playMode: 'hover' }); // Click — plays one burst on each click PowerGlitch.glitch('.logo', { playMode: 'click' }); // Manual — animation never starts until startGlitch() is called explicitly const { startGlitch, stopGlitch } = PowerGlitch.glitch('.logo', { playMode: 'manual', }); document.querySelector('#trigger').addEventListener('click', () => { stopGlitch(); // cancel any in-progress animation startGlitch(); // start a fresh burst }); ``` -------------------------------- ### PowerGlitch.generateLayers Source: https://github.com/7ph/powerglitch/blob/master/docs/api-docs/variables/PowerGlitch.html Generates the layers that deterministically define a glitch animation based on the provided options. ```APIDOC ## PowerGlitch.generateLayers ### Description Generate the layers that deterministically define a glitch animation for the specified options. ### Method (options: [PowerGlitchOptions]): [LayerDefinition][] ### Parameters #### Path Parameters - **options** ([PowerGlitchOptions]): Configuration options for generating glitch layers. ### Returns [LayerDefinition][] ``` -------------------------------- ### Shake Layer - `shake` Option Source: https://context7.com/7ph/powerglitch/llms.txt Controls the base layer that shakes the element, allowing for customization or complete disabling of the shaking effect. ```APIDOC ## Shake Layer — `shake` option ### Description Controls the base layer that shakes the element as a whole. Set to `false` to disable shaking entirely. ### Parameters - `velocity` (number): Steps per second for the shake layer. Higher values result in smoother but potentially heavier animations. - `amplitudeX` (number): Maximum horizontal displacement as a fraction of the element's width. - `amplitudeY` (number): Maximum vertical displacement as a fraction of the element's height. ### Usage Examples ```javascript import { PowerGlitch } from 'powerglitch'; // Aggressive screen-shake effect PowerGlitch.glitch('.glitch', { shake: { velocity: 25, // more steps = smoother but heavier amplitudeX: 0.5, // 50 % of element width amplitudeY: 0.05, // subtle vertical movement }, }); // Disable shaking — slice layers only PowerGlitch.glitch('.glitch', { shake: false, slice: { count: 8, hueRotate: true, cssFilters: '' }, }); ``` ``` -------------------------------- ### Slice Layers Configuration Source: https://context7.com/7ph/powerglitch/llms.txt Configure the slice layer effect for creating glitch aesthetics. This involves defining the number, size, and velocity of horizontal strips that are randomly clipped and translated. ```APIDOC ## Slice Layers — `slice` option Slice layers are the primary source of the glitch aesthetic. Each slice layer randomly clips a horizontal strip of the element and translates it sideways with an optional color filter. ```js import { PowerGlitch } from 'powerglitch'; // Many thin, fast slices with custom CSS filters PowerGlitch.glitch('.glitch', { slice: { count: 15, // 15 simultaneous slice layers velocity: 20, // 20 keyframes per second minHeight: 0.01, // very thin slices (1 %) maxHeight: 0.10, // max 10 % of element height hueRotate: false, // disable default hue rotation cssFilters: 'blur(2px) brightness(1.4)',// custom filter per active slice }, }); // Disable hueRotate and apply no filter at all PowerGlitch.glitch('.glitch', { slice: { count: 6, velocity: 15, minHeight: 0.02, maxHeight: 0.15, hueRotate: false, cssFilters: '', }, }); ``` ``` -------------------------------- ### Pulse Layer Configuration Source: https://context7.com/7ph/powerglitch/llms.txt Configure the pulse layer effect, which adds a transparent, scaling copy of the element that radiates outward. This can be disabled by setting it to `false`. ```APIDOC ## Pulse Layer — `pulse` option Adds a transparent, scaling copy of the element that radiates outward during the glitch window. Set to `false` (default) to disable. ```js import { PowerGlitch } from 'powerglitch'; // Subtle pulse that radiates to 1.3× the element size PowerGlitch.glitch('.glitch', { pulse: { scale: 1.3 }, glitchTimeSpan: { start: 0.5, end: 0.7 }, }); // Large dramatic pulse combined with slices and no shake PowerGlitch.glitch('.glitch', { shake: false, pulse: { scale: 2.5 }, slice: { count: 3 }, glitchTimeSpan: { start: 0.0, end: 1.0 }, }); ``` ``` -------------------------------- ### PowerGlitch Shake Layer Options Source: https://context7.com/7ph/powerglitch/llms.txt Customize the shake layer using the `shake` option. Set `shake: false` to disable shaking entirely. Adjust `velocity`, `amplitudeX`, and `amplitudeY` for desired effect. ```javascript import { PowerGlitch } from 'powerglitch'; // Aggressive screen-shake effect PowerGlitch.glitch('.glitch', { shake: { velocity: 25, // more steps = smoother but heavier amplitudeX: 0.5, // 50 % of element width amplitudeY: 0.05, // subtle vertical movement }, }); // Disable shaking — slice layers only PowerGlitch.glitch('.glitch', { shake: false, slice: { count: 8, hueRotate: true, cssFilters: '' }, }); ``` -------------------------------- ### Deep-merge option objects with mergeOptions() Source: https://context7.com/7ph/powerglitch/llms.txt Use mergeOptions() for immutable deep merging of plain objects. It's useful for combining user options with defaults or building reusable option presets. Arrays are not merged. ```javascript import { mergeOptions, PowerGlitch } from 'powerglitch'; // Build a reusable preset const subtlePreset = { timing: { duration: 3000 }, shake: { amplitudeX: 0.1, amplitudeY: 0.1 }, slice: { count: 3, hueRotate: false }, }; // Override just the timing for a specific element const specificOptions = mergeOptions( PowerGlitch.getDefaultOptions('always'), subtlePreset, { timing: { duration: 500 } } // wins — applied last ); console.log(specificOptions.timing.duration); // 500 console.log(specificOptions.slice.count); // 3 (from subtlePreset) console.log(specificOptions.shake.velocity); // 15 (from getDefaultOptions) PowerGlitch.glitch('.logo', specificOptions); ``` -------------------------------- ### Configure Pulse Layer for Radiating Effect Source: https://context7.com/7ph/powerglitch/llms.txt The `pulse` option adds a transparent, scaling copy of the element that radiates outward. Adjust the `scale` property to control the size of the pulse. ```javascript import { PowerGlitch } from 'powerglitch'; // Subtle pulse that radiates to 1.3× the element size PowerGlitch.glitch('.glitch', { pulse: { scale: 1.3 }, glitchTimeSpan: { start: 0.5, end: 0.7 }, }); // Large dramatic pulse combined with slices and no shake PowerGlitch.glitch('.glitch', { shake: false, pulse: { scale: 2.5 }, slice: { count: 3 }, glitchTimeSpan: { start: 0.0, end: 1.0 }, }); ``` -------------------------------- ### mergeOptions Source: https://github.com/7ph/powerglitch/blob/master/docs/api-docs/functions/mergeOptions.html Performs a deep merge of option objects and returns a new object. This function is immutable and will ignore arrays. ```APIDOC ## Function mergeOptions ### Description Performs a deep merge of option objects and returns a new object. Does not modify objects (immutable) and will ignore arrays. ### Parameters #### Rest Parameters * **...objects** (readonly any[]) - Required - Objects to merge ### Returns New object with merged key/values ``` -------------------------------- ### PowerGlitchOptions Type Definition Source: https://github.com/7ph/powerglitch/blob/master/docs/api-docs/types/PowerGlitchOptions.html This type alias defines the structure for custom options used to configure glitch animations in PowerGlitch. It includes various properties to control aspects like SEO optimization, HTML content, animation play modes, overflow hiding, timing, glitch duration, shake effects, slice properties, and pulse scaling. ```APIDOC Type alias PowerGlitchOptions ============================= PowerGlitchOptions: { optimizeSeo: boolean; html?: string; createContainers: boolean; playMode: [PlayModes](PlayModes.html); hideOverflow: boolean; timing: { duration: number; iterations: number; easing?: string; }; glitchTimeSpan: false | { start: number; end: number; }; shake: false | { velocity: number; amplitudeX: number; amplitudeY: number; }; slice: { count: number; velocity: number; minHeight: number; maxHeight: number; hueRotate: boolean; cssFilters: string; }; pulse: false | { scale: number; }; } Custom options for the glitch animations. ``` -------------------------------- ### Manual DOM layout control with createContainers: false Source: https://context7.com/7ph/powerglitch/llms.txt Set createContainers: false to disable default wrapper divs and use a pre-built structure. The target element becomes the layer container, and its first child is the element to glitch. This is useful in framework components where DOM structure is managed externally. ```html
Hello World
Injected content
', }); ``` ```javascript // ── Full options example ─────────────────────────────────── const { containers, startGlitch, stopGlitch } = PowerGlitch.glitch('.glitch', { playMode: 'always', // 'always' | 'hover' | 'click' | 'manual' optimizeSeo: true, // skip animation for known web crawlers createContainers: true, // let PowerGlitch manage the wrapper DOM hideOverflow: true, // clip slices that go outside the element bounds timing: { duration: 2000, // animation loop length in ms iterations: Infinity, // repeat count (Infinity = loop forever) easing: 'ease-in-out', // CSS easing for all layers }, glitchTimeSpan: { start: 0.4, // glitch starts at 40 % of each loop end: 0.7, // glitch ends at 70 % of each loop }, shake: { velocity: 15, // steps per second for the shake layer amplitudeX: 0.2, // max X displacement as fraction of width amplitudeY: 0.2, // max Y displacement as fraction of height }, slice: { count: 6, // number of clipping/translating slice layers velocity: 15, // steps per second for slice layers minHeight: 0.02, // min slice height as fraction of element height maxHeight: 0.15, // max slice height as fraction of element height hueRotate: true, // apply random hue-rotation to each slice cssFilters: '', // custom CSS filter string; overrides hueRotate }, pulse: false, // or { scale: 1.5 } to add a pulsing layer }); // containers: HTMLDivElement[] — the top-level wrappers around each glitched element console.log('Wrapper elements:', containers); // Programmatically pause and resume the animation stopGlitch(); setTimeout(startGlitch, 1000); ``` -------------------------------- ### PlayModes Type Definition Source: https://github.com/7ph/powerglitch/blob/master/docs/api-docs/types/PlayModes.html This type alias defines the possible string values that can be used to configure the play mode of the glitch effect. ```APIDOC Type alias PlayModes PlayModes: "always" | "hover" | "click" | "manual" Available play modes Remarks: * always: Always glitch (default) * hover: Glitch on hover * click: Glitch will start on each click * manual: Glitch controlled with returned callbacks Defined in [index.ts:9](https://github.com/7PH/powerglitch/blob/7ab2b8c/src/index.ts#L9) ``` -------------------------------- ### Apply glitch effect to elements Source: https://github.com/7ph/powerglitch/blob/master/README.md Use the PowerGlitch.glitch() method, passing a CSS selector, to apply the glitch effect to the selected elements. This is the core function to activate the glitch. ```javascript PowerGlitch.glitch('.glitch') ``` -------------------------------- ### Select elements to glitch Source: https://github.com/7ph/powerglitch/blob/master/README.md Add the 'glitch' class to any HTML element you want to apply the glitch effect to. This includes images, buttons, or any other DOM element. ```html
```
```html
```
```html
Hello World