Browser detection, color management, utility functions, debugging tools, and performance optimization helpers. These utilities provide essential functionality for feature detection, data manipulation, and application optimization.
Functions for detecting browser capabilities and device types.
/**
* Check if running on mobile device
* @returns True if mobile device detected
*/
function isMobile(): boolean;
/**
* Check if WebGL is supported
* @returns True if WebGL is supported
*/
function isWebGLSupported(): boolean;
/**
* Check if WebGPU is supported
* @returns Promise resolving to WebGPU support status
*/
function isWebGPUSupported(): Promise<boolean>;
/**
* Check if running in Safari browser
* @returns True if Safari detected
*/
function isSafari(): boolean;
/**
* Check if unsafe eval is supported
* @returns True if eval is available
*/
function unsafeEvalSupported(): boolean;
/**
* Detect video alpha mode support
* @returns Promise resolving to alpha mode support
*/
function detectVideoAlphaMode(): Promise<boolean>;Comprehensive color class with multiple format support and manipulation.
/**
* Color class supporting multiple formats and operations
*/
class Color {
constructor(value?: ColorSource);
/** Numeric color value */
readonly value: number;
/** Alpha channel (0-1) */
readonly alpha: number;
/**
* Set color value
* @param value - Color in any supported format
* @returns This color instance
*/
setValue(value: ColorSource): this;
/**
* Set alpha channel
* @param alpha - Alpha value (0-1)
* @returns This color instance
*/
setAlpha(alpha: number): this;
/**
* Convert to hex string
* @returns Hex color string (e.g., "#ff0000")
*/
toHex(): string;
/**
* Convert to RGBA array
* @returns RGBA values [r, g, b, a] (0-1)
*/
toRgba(): [number, number, number, number];
/**
* Convert to RGB object
* @returns RGB object with r, g, b properties (0-255)
*/
toRgb(): { r: number; g: number; b: number };
/**
* Convert to HSL array
* @returns HSL values [h, s, l] (h: 0-360, s,l: 0-1)
*/
toHsl(): [number, number, number];
/**
* Convert to HSV array
* @returns HSV values [h, s, v] (h: 0-360, s,v: 0-1)
*/
toHsv(): [number, number, number];
/**
* Multiply color by another color
* @param value - Color to multiply by
* @returns New color result
*/
multiply(value: ColorSource): Color;
/**
* Add color to another color
* @param value - Color to add
* @returns New color result
*/
add(value: ColorSource): Color;
/**
* Subtract color from another color
* @param value - Color to subtract
* @returns New color result
*/
subtract(value: ColorSource): Color;
/**
* Brighten color
* @param amount - Brighten amount (0-1)
* @returns New brightened color
*/
brighten(amount: number): Color;
/**
* Darken color
* @param amount - Darken amount (0-1)
* @returns New darkened color
*/
darken(amount: number): Color;
/**
* Desaturate color
* @param amount - Desaturation amount (0-1)
* @returns New desaturated color
*/
desaturate(amount: number): Color;
/**
* Get grayscale version
* @returns Grayscale color
*/
grayscale(): Color;
/**
* Clone color
* @returns New color with same values
*/
clone(): Color;
/**
* Check if value is color-like
* @param value - Value to check
* @returns True if color-like
*/
static isColorLike(value: any): value is ColorSource;
/**
* Convert hex string to number
* @param hex - Hex string
* @returns Numeric color value
*/
static hexToNumber(hex: string): number;
/**
* Convert number to hex string
* @param value - Numeric color
* @returns Hex string
*/
static numberToHex(value: number): string;
/** Shared color instance for temp calculations */
static readonly shared: Color;
}
/**
* Color source types
*/
type ColorSource =
| number // 0xff0000
| string // "#ff0000", "red", "rgb(255,0,0)"
| Color // Color instance
| [number, number, number] // RGB array
| [number, number, number, number] // RGBA array
| { r: number; g: number; b: number; a?: number }; // RGB objectSystem for generating unique identifiers.
/**
* Generate unique identifier
* @returns Unique number ID
*/
function uid(): number;
/**
* Create ID from string
* @param value - String to convert
* @returns Numeric ID
*/
function createIdFromString(value: string): number;Utilities for data manipulation and management.
/**
* ViewableBuffer for efficient data handling
*/
class ViewableBuffer {
constructor(arrayBuffer: ArrayBuffer | SharedArrayBuffer, size?: number);
/** Raw array buffer */
readonly rawBinaryData: ArrayBuffer | SharedArrayBuffer;
/** Uint32 view of buffer */
uint32View: Uint32Array;
/** Float32 view of buffer */
float32View: Float32Array;
/** Buffer size */
size: number;
/**
* Destroy buffer and views
*/
destroy(): void;
/**
* Ensure buffer has minimum size
* @param requestedSize - Minimum required size
*/
ensureCapacity(requestedSize: number): void;
}
/**
* Remove items from array
* @param arr - Array to modify
* @param startIdx - Start index
* @param removeCount - Number of items to remove
* @returns Modified array
*/
function removeItems<T>(arr: T[], startIdx: number, removeCount: number): T[];
/**
* Clean/trim array by removing falsy values
* @param arr - Array to clean
* @returns Cleaned array
*/
function clean<T>(arr: T[]): T[];
/**
* Update quad bounds efficiently
* @param bounds - Bounds to update
* @param x1 - First X coordinate
* @param y1 - First Y coordinate
* @param x2 - Second X coordinate
* @param y2 - Second Y coordinate
* @param x3 - Third X coordinate
* @param y3 - Third Y coordinate
* @param x4 - Fourth X coordinate
* @param y4 - Fourth Y coordinate
*/
function updateQuadBounds(bounds: Rectangle, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;Memory management through object pooling for performance optimization.
/**
* Generic object pool for reusing objects
*/
class Pool<T> {
constructor(ClassType: new () => T, resetFunction?: (item: T) => void);
/**
* Get object from pool
* @returns Pooled object
*/
get(): T;
/**
* Return object to pool
* @param item - Object to return
*/
return(item: T): void;
/**
* Clear all pooled objects
*/
clear(): void;
/** Number of objects in pool */
readonly count: number;
}
/**
* Pool group for managing multiple pools
*/
class PoolGroup {
constructor();
/**
* Get pool for class type
* @param ClassType - Class constructor
* @param resetFunction - Reset function for objects
* @returns Pool instance
*/
getPool<T>(ClassType: new () => T, resetFunction?: (item: T) => void): Pool<T>;
/**
* Clear all pools
*/
clear(): void;
}Transform and matrix manipulation utilities.
/**
* Transform class for object transformations
*/
class Transform {
constructor();
/** Local transformation matrix */
localTransform: Matrix;
/** World transformation matrix */
worldTransform: Matrix;
/** Position */
position: ObservablePoint;
/** Scale */
scale: ObservablePoint;
/** Pivot point */
pivot: ObservablePoint;
/** Skew */
skew: ObservablePoint;
/** Rotation in radians */
rotation: number;
/**
* Update local transform
*/
updateLocalTransform(): void;
/**
* Update world transform
* @param parentTransform - Parent transform
*/
updateTransform(parentTransform: Transform): void;
/**
* Set from matrix
* @param matrix - Matrix to apply
* @returns This transform
*/
setFromMatrix(matrix: Matrix): this;
}Debugging utilities and logging functions.
/**
* Log warning message
* @param message - Warning message
* @param ...args - Additional arguments
*/
function warn(message: string, ...args: any[]): void;
/**
* Show deprecation warning
* @param version - Version when deprecated
* @param message - Deprecation message
* @param ignoreDepth - Stack trace depth to ignore
*/
function deprecation(version: string, message: string, ignoreDepth?: number): void;
/**
* Log debug information about texture
* @param texture - Texture to debug
* @param renderer - Renderer instance
*/
function logDebugTexture(texture: Texture, renderer: Renderer): void;
/**
* Log scene graph structure
* @param container - Container to log
* @param depth - Current depth level
*/
function logScene(container: Container, depth?: number): void;Network and URL utilities.
/**
* Get resolution from URL
* @param url - URL to analyze
* @returns Resolution multiplier
*/
function getResolutionOfUrl(url: string): number;Canvas manipulation and measurement utilities.
/**
* Get canvas bounding box
* @param canvas - Canvas element
* @param resolution - Resolution multiplier
* @returns Bounding rectangle
*/
function getCanvasBoundingBox(canvas: HTMLCanvasElement, resolution?: number): Rectangle;Path manipulation and parsing utilities.
/**
* Parse path string into components
* @param path - Path string
* @returns Path components
*/
function parsePath(path: string): PathComponent[];
/**
* Join path components
* @param ...components - Path components to join
* @returns Joined path string
*/
function joinPath(...components: string[]): string;
interface PathComponent {
/** Component type */
type: 'directory' | 'file' | 'extension';
/** Component value */
value: string;
}Usage Examples:
import {
Color,
isMobile,
isWebGLSupported,
uid,
Pool,
Transform,
warn,
getResolutionOfUrl
} from 'pixi.js';
// Browser detection
if (isMobile()) {
console.log('Running on mobile device');
}
if (await isWebGLSupported()) {
console.log('WebGL is supported');
}
// Color manipulation
const color = new Color('#ff0000');
console.log(color.toHex()); // "#ff0000"
console.log(color.toRgba()); // [1, 0, 0, 1]
const brightRed = color.brighten(0.2);
const darkRed = color.darken(0.3);
const grayRed = color.desaturate(0.5);
// Multiple color formats
const colors = [
new Color(0xff0000), // Number
new Color('#00ff00'), // Hex string
new Color('blue'), // Named color
new Color([255, 255, 0]), // RGB array
new Color({ r: 255, g: 0, b: 255, a: 0.5 }) // RGBA object
];
// Unique ID generation
const id1 = uid(); // Unique number
const id2 = uid(); // Different unique number
// Object pooling for performance
class Particle {
x = 0;
y = 0;
reset() {
this.x = 0;
this.y = 0;
}
}
const particlePool = new Pool(Particle, (particle) => particle.reset());
// Use particles
const particle1 = particlePool.get();
particle1.x = 100;
particle1.y = 200;
// Return to pool when done
particlePool.return(particle1);
// Transform utilities
const transform = new Transform();
transform.position.set(100, 100);
transform.scale.set(2, 2);
transform.rotation = Math.PI / 4;
transform.updateLocalTransform();
// Apply transform to sprite
const sprite = new Sprite(texture);
sprite.transform = transform;
// Debugging and logging
if (process.env.NODE_ENV === 'development') {
warn('This is a warning message');
logScene(app.stage);
}
// Network utilities
const imageUrl = 'images/sprite@2x.png';
const resolution = getResolutionOfUrl(imageUrl); // Returns 2
// Feature detection with fallbacks
async function initializeRenderer() {
if (await isWebGPUSupported()) {
return new WebGPURenderer();
} else if (isWebGLSupported()) {
return new WebGLRenderer();
} else {
throw new Error('No supported renderer available');
}
}
// Color themes
const theme = {
primary: new Color('#3498db'),
secondary: new Color('#2ecc71'),
danger: new Color('#e74c3c'),
warning: new Color('#f39c12')
};
// Dynamic color adjustments
function adjustThemeForTime(hour: number) {
const brightness = hour < 6 || hour > 18 ? 0.3 : 0; // Darker at night
return {
primary: theme.primary.darken(brightness),
secondary: theme.secondary.darken(brightness),
danger: theme.danger.darken(brightness),
warning: theme.warning.darken(brightness)
};
}