physics-glass-effects
Version:
Physics-based glass effects using WebGL with real optical science - works with React, Vue, Next.js, and vanilla JS
139 lines • 4.12 kB
TypeScript
/**
* Glass shape types available in the physics engine
*/
export type GlassShape = 'sphere' | 'cylinder' | 'lens' | 'prism' | 'flat';
/**
* Background pattern types for demonstrating distortion effects
*/
export type BackgroundPattern = 'stripes' | 'grid' | 'circles' | 'texture';
/**
* Glass material presets with realistic optical properties
*/
export interface GlassMaterial {
name: string;
refractionIndex: number;
dispersion: number;
description: string;
}
/**
* Mouse interaction configuration
*/
export interface MouseConfig {
enabled: boolean;
followCursor: boolean;
centerX?: number;
centerY?: number;
}
/**
* Rendering performance configuration
*/
export interface PerformanceConfig {
pixelRatio?: number;
antialias?: boolean;
preserveDrawingBuffer?: boolean;
premultipliedAlpha?: boolean;
}
/**
* Animation configuration
*/
export interface AnimationConfig {
enabled: boolean;
speed: number;
surfaceRipples: boolean;
}
/**
* Complete configuration object for PhysicsGlass
*/
export interface PhysicsGlassConfig {
shape?: GlassShape;
size?: number;
refractionIndex?: number;
dispersion?: number;
thickness?: number;
backgroundPattern?: BackgroundPattern;
backgroundTexture?: HTMLImageElement | HTMLCanvasElement | string;
mouse?: MouseConfig;
animation?: AnimationConfig;
performance?: PerformanceConfig;
onReady?: () => void;
onError?: (error: Error) => void;
onShapeChange?: (shape: GlassShape) => void;
onMaterialChange?: (material: GlassMaterial) => void;
}
/**
* Internal uniform values passed to shaders
*/
export interface ShaderUniforms {
time: number;
resolution: [number, number];
mousePos: [number, number];
refractionIndex: number;
dispersion: number;
thickness: number;
glassSize: number;
glassShape: number;
backgroundPattern: number;
}
/**
* WebGL context and program management
*/
export interface WebGLState {
gl: WebGL2RenderingContext | WebGLRenderingContext;
program: WebGLProgram;
uniformLocations: Record<string, WebGLUniformLocation | null>;
backgroundTexture: WebGLTexture | null;
}
/**
* Canvas lifecycle events
*/
export interface CanvasEvents {
resize: () => void;
mousemove: (event: MouseEvent) => void;
mouseenter: (event: MouseEvent) => void;
mouseleave: (event: MouseEvent) => void;
contextlost: (event: WebGLContextEvent) => void;
contextrestored: (event: WebGLContextEvent) => void;
}
/**
* Public API methods for the PhysicsGlass instance
*/
export interface PhysicsGlassAPI {
setShape(shape: GlassShape): void;
setSize(size: number): void;
setRefractionIndex(index: number): void;
setDispersion(dispersion: number): void;
setThickness(thickness: number): void;
setBackgroundPattern(pattern: BackgroundPattern): void;
setBackgroundTexture(texture: HTMLImageElement | HTMLCanvasElement | string): Promise<void>;
setMaterial(material: GlassMaterial | string): void;
getMaterials(): GlassMaterial[];
setMousePosition(x: number, y: number): void;
enableMouseTracking(enabled: boolean): void;
startAnimation(): void;
stopAnimation(): void;
setAnimationSpeed(speed: number): void;
destroy(): void;
resize(): void;
getConfig(): PhysicsGlassConfig;
getCanvas(): HTMLCanvasElement;
isWebGLSupported(): boolean;
}
/**
* Predefined glass materials with realistic properties
*/
export declare const GLASS_MATERIALS: Record<string, GlassMaterial>;
/**
* Error types that can be thrown by the library
*/
export declare class PhysicsGlassError extends Error {
code: string;
constructor(message: string, code: string);
}
export declare const ERROR_CODES: {
readonly WEBGL_NOT_SUPPORTED: "WEBGL_NOT_SUPPORTED";
readonly CANVAS_NOT_FOUND: "CANVAS_NOT_FOUND";
readonly SHADER_COMPILATION_FAILED: "SHADER_COMPILATION_FAILED";
readonly TEXTURE_LOAD_FAILED: "TEXTURE_LOAD_FAILED";
readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
};
//# sourceMappingURL=types.d.ts.map