react-confetti-burst 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +303 -0
- package/dist/cjs/components.d.ts +219 -0
- package/dist/cjs/components.d.ts.map +1 -0
- package/dist/cjs/components.js +341 -0
- package/dist/cjs/components.js.map +1 -0
- package/dist/cjs/confetti-engine.d.ts +122 -0
- package/dist/cjs/confetti-engine.d.ts.map +1 -0
- package/dist/cjs/confetti-engine.js +589 -0
- package/dist/cjs/confetti-engine.js.map +1 -0
- package/dist/cjs/confetti.d.ts +50 -0
- package/dist/cjs/confetti.d.ts.map +1 -0
- package/dist/cjs/confetti.js +446 -0
- package/dist/cjs/confetti.js.map +1 -0
- package/dist/cjs/constants.d.ts +147 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +609 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/hooks.d.ts +94 -0
- package/dist/cjs/hooks.d.ts.map +1 -0
- package/dist/cjs/hooks.js +225 -0
- package/dist/cjs/hooks.js.map +1 -0
- package/dist/cjs/index.d.ts +34 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +180 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/particle.d.ts +50 -0
- package/dist/cjs/particle.d.ts.map +1 -0
- package/dist/cjs/particle.js +475 -0
- package/dist/cjs/particle.js.map +1 -0
- package/dist/cjs/shapes.d.ts +190 -0
- package/dist/cjs/shapes.d.ts.map +1 -0
- package/dist/cjs/shapes.js +272 -0
- package/dist/cjs/shapes.js.map +1 -0
- package/dist/cjs/types.d.ts +720 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +25 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +90 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +330 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/components.js +334 -0
- package/dist/esm/components.js.map +1 -0
- package/dist/esm/confetti-engine.js +581 -0
- package/dist/esm/confetti-engine.js.map +1 -0
- package/dist/esm/confetti.js +443 -0
- package/dist/esm/confetti.js.map +1 -0
- package/dist/esm/constants.js +605 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/hooks.js +218 -0
- package/dist/esm/hooks.js.map +1 -0
- package/dist/esm/index.js +146 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/particle.js +465 -0
- package/dist/esm/particle.js.map +1 -0
- package/dist/esm/shapes.js +265 -0
- package/dist/esm/shapes.js.map +1 -0
- package/dist/esm/types.js +24 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.js +309 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/components.d.ts +219 -0
- package/dist/types/components.d.ts.map +1 -0
- package/dist/types/confetti-engine.d.ts +122 -0
- package/dist/types/confetti-engine.d.ts.map +1 -0
- package/dist/types/confetti.d.ts +50 -0
- package/dist/types/confetti.d.ts.map +1 -0
- package/dist/types/constants.d.ts +147 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/hooks.d.ts +94 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/particle.d.ts +50 -0
- package/dist/types/particle.d.ts.map +1 -0
- package/dist/types/shapes.d.ts +190 -0
- package/dist/types/shapes.d.ts.map +1 -0
- package/dist/types/types.d.ts +720 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +90 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for react-confetti-burst
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive TypeScript definitions for all
|
|
5
|
+
* configuration options, particle properties, and animation states.
|
|
6
|
+
*
|
|
7
|
+
* Features beyond react-confetti AND canvas-confetti:
|
|
8
|
+
* - Directional bursts with custom angles
|
|
9
|
+
* - Multiple effect modes (burst, continuous, firework, snow, cannon)
|
|
10
|
+
* - Custom draw functions with full context
|
|
11
|
+
* - Emoji and image particle support
|
|
12
|
+
* - Trails and glow effects
|
|
13
|
+
* - Preset configurations
|
|
14
|
+
* - Auto-resize support
|
|
15
|
+
* - Frame rate control
|
|
16
|
+
* - Spawn area configuration
|
|
17
|
+
* - SVG path shapes (shapeFromPath)
|
|
18
|
+
* - Text/emoji shapes (shapeFromText)
|
|
19
|
+
* - Web Worker rendering (useWorker)
|
|
20
|
+
* - Reduced motion accessibility
|
|
21
|
+
* - Custom canvas support
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Represents a 2D point in space
|
|
25
|
+
*/
|
|
26
|
+
export interface Point {
|
|
27
|
+
readonly x: number;
|
|
28
|
+
readonly y: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Normalized origin (0-1 coordinates like canvas-confetti)
|
|
32
|
+
*/
|
|
33
|
+
export interface NormalizedOrigin {
|
|
34
|
+
/** X position (0 = left, 1 = right). Default: 0.5 */
|
|
35
|
+
readonly x: number;
|
|
36
|
+
/** Y position (0 = top, 1 = bottom). Default: 0.5 */
|
|
37
|
+
readonly y: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Represents a 2D vector for physics calculations
|
|
41
|
+
*/
|
|
42
|
+
export interface Vector2D {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* RGBA color representation
|
|
48
|
+
*/
|
|
49
|
+
export interface RGBAColor {
|
|
50
|
+
readonly r: number;
|
|
51
|
+
readonly g: number;
|
|
52
|
+
readonly b: number;
|
|
53
|
+
readonly a: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gradient color for particles
|
|
57
|
+
*/
|
|
58
|
+
export interface GradientColor {
|
|
59
|
+
readonly type: 'linear' | 'radial';
|
|
60
|
+
readonly colors: readonly string[];
|
|
61
|
+
readonly angle?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Supported color formats for confetti particles
|
|
65
|
+
*/
|
|
66
|
+
export type ColorInput = string | RGBAColor | GradientColor;
|
|
67
|
+
/**
|
|
68
|
+
* Bounds for a path shape
|
|
69
|
+
*/
|
|
70
|
+
export interface PathBounds {
|
|
71
|
+
readonly minX: number;
|
|
72
|
+
readonly minY: number;
|
|
73
|
+
readonly maxX: number;
|
|
74
|
+
readonly maxY: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Custom shape created from SVG path (canvas-confetti compatible)
|
|
78
|
+
*/
|
|
79
|
+
export interface PathShape {
|
|
80
|
+
readonly type: 'path';
|
|
81
|
+
/** SVG path string (d attribute) */
|
|
82
|
+
readonly path: string;
|
|
83
|
+
/** Optional 2D transformation matrix [a, b, c, d, e, f] */
|
|
84
|
+
readonly matrix?: DOMMatrix | readonly number[];
|
|
85
|
+
/** Optional fill color (uses particle color if not set) */
|
|
86
|
+
readonly fillColor?: string;
|
|
87
|
+
/** Optional stroke color */
|
|
88
|
+
readonly strokeColor?: string;
|
|
89
|
+
/** Optional stroke width */
|
|
90
|
+
readonly strokeWidth?: number;
|
|
91
|
+
/** Calculated path bounds for scaling */
|
|
92
|
+
readonly bounds?: PathBounds;
|
|
93
|
+
/** Cached Path2D object for performance */
|
|
94
|
+
readonly _path2D?: Path2D;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Custom shape created from text/emoji (canvas-confetti compatible)
|
|
98
|
+
*/
|
|
99
|
+
export interface TextShape {
|
|
100
|
+
readonly type: 'text';
|
|
101
|
+
/** Text or emoji to render */
|
|
102
|
+
readonly text: string;
|
|
103
|
+
/** Scale factor. Default: 1 */
|
|
104
|
+
readonly scalar?: number;
|
|
105
|
+
/** Text color (uses particle color if not set) */
|
|
106
|
+
readonly color?: string;
|
|
107
|
+
/** Font family. Default: 'serif' */
|
|
108
|
+
readonly fontFamily?: string;
|
|
109
|
+
/** Font weight. Default: 'normal' */
|
|
110
|
+
readonly fontWeight?: string;
|
|
111
|
+
/** Font style. Default: 'normal' */
|
|
112
|
+
readonly fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
113
|
+
/** Cached bitmap for performance */
|
|
114
|
+
readonly _bitmap?: ImageBitmap | HTMLCanvasElement;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Custom shape union type
|
|
118
|
+
*/
|
|
119
|
+
export type CustomShape = PathShape | TextShape;
|
|
120
|
+
/**
|
|
121
|
+
* Shape types for confetti particles
|
|
122
|
+
*/
|
|
123
|
+
export type ParticleShape = 'square' | 'circle' | 'rectangle' | 'triangle' | 'star' | 'line' | 'heart' | 'diamond' | 'hexagon' | 'spiral' | 'ribbon' | 'custom' | CustomShape;
|
|
124
|
+
/**
|
|
125
|
+
* Shape input (string or custom shape object)
|
|
126
|
+
*/
|
|
127
|
+
export type ShapeInput = Exclude<ParticleShape, CustomShape> | CustomShape;
|
|
128
|
+
/**
|
|
129
|
+
* Direction presets for confetti bursts
|
|
130
|
+
*/
|
|
131
|
+
export type BurstDirection = 'up' | 'down' | 'left' | 'right' | 'radial' | 'custom';
|
|
132
|
+
/**
|
|
133
|
+
* Effect mode for confetti
|
|
134
|
+
*/
|
|
135
|
+
export type EffectMode = 'burst' | 'continuous' | 'firework' | 'snow' | 'cannon' | 'fountain' | 'rain' | 'explosion';
|
|
136
|
+
/**
|
|
137
|
+
* Easing function type for animations
|
|
138
|
+
*/
|
|
139
|
+
export type EasingFunction = (t: number) => number;
|
|
140
|
+
/**
|
|
141
|
+
* Easing preset names
|
|
142
|
+
*/
|
|
143
|
+
export type EasingPreset = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'bounce' | 'elastic' | 'back' | 'circ' | 'expo';
|
|
144
|
+
/**
|
|
145
|
+
* Custom draw function context
|
|
146
|
+
*/
|
|
147
|
+
export interface DrawContext {
|
|
148
|
+
/** Canvas 2D rendering context */
|
|
149
|
+
readonly ctx: CanvasRenderingContext2D;
|
|
150
|
+
/** Particle being drawn */
|
|
151
|
+
readonly particle: ParticleState;
|
|
152
|
+
/** Current progress (0-1) */
|
|
153
|
+
readonly progress: number;
|
|
154
|
+
/** Time since animation started (ms) */
|
|
155
|
+
readonly elapsed: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Custom draw function type
|
|
159
|
+
*/
|
|
160
|
+
export type CustomDrawFunction = (context: DrawContext) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Configuration for particle physics behavior
|
|
163
|
+
*/
|
|
164
|
+
export interface PhysicsConfig {
|
|
165
|
+
/** Gravity strength (positive = downward). Default: 0.3 */
|
|
166
|
+
readonly gravity: number;
|
|
167
|
+
/** Air resistance factor (0-1). Default: 0.02 */
|
|
168
|
+
readonly drag: number;
|
|
169
|
+
/** Friction coefficient (0-1). Default: 0.99 */
|
|
170
|
+
readonly friction: number;
|
|
171
|
+
/** Rotation speed multiplier. Default: 1 */
|
|
172
|
+
readonly rotationSpeed: number;
|
|
173
|
+
/** Wind force applied horizontally. Default: 0 */
|
|
174
|
+
readonly wind: number;
|
|
175
|
+
/** Wind variation range. Default: 0 */
|
|
176
|
+
readonly windVariation: number;
|
|
177
|
+
/** Whether particles should tumble/rotate. Default: true */
|
|
178
|
+
readonly tumble: boolean;
|
|
179
|
+
/** Velocity decay per frame (0-1). Default: 0.98 */
|
|
180
|
+
readonly decay: number;
|
|
181
|
+
/** Bounce factor when hitting edges (0 = no bounce, 1 = full). Default: 0 */
|
|
182
|
+
readonly bounce: number;
|
|
183
|
+
/** Floor Y position for bouncing (null = no floor). Default: null */
|
|
184
|
+
readonly floor: number | null;
|
|
185
|
+
/** Enable 3D wobble effect. Default: false */
|
|
186
|
+
readonly wobble: boolean;
|
|
187
|
+
/** Wobble speed. Default: 1 */
|
|
188
|
+
readonly wobbleSpeed: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Configuration for the burst direction and spread
|
|
192
|
+
*/
|
|
193
|
+
export interface DirectionConfig {
|
|
194
|
+
/** Direction preset or 'custom' for manual angle. Default: 'up' */
|
|
195
|
+
readonly direction: BurstDirection;
|
|
196
|
+
/** Custom angle in degrees (0 = right, 90 = up). Used when direction is 'custom' */
|
|
197
|
+
readonly angle?: number;
|
|
198
|
+
/** Spread angle in degrees for the burst cone. Default: 45 */
|
|
199
|
+
readonly spread: number;
|
|
200
|
+
/** Initial velocity range [min, max]. Default: [20, 40] */
|
|
201
|
+
readonly velocity: readonly [number, number];
|
|
202
|
+
/** Initial velocity X range { min, max } (alternative to velocity/angle) */
|
|
203
|
+
readonly initialVelocityX?: {
|
|
204
|
+
readonly min: number;
|
|
205
|
+
readonly max: number;
|
|
206
|
+
} | number;
|
|
207
|
+
/** Initial velocity Y range { min, max } (alternative to velocity/angle) */
|
|
208
|
+
readonly initialVelocityY?: {
|
|
209
|
+
readonly min: number;
|
|
210
|
+
readonly max: number;
|
|
211
|
+
} | number;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Spawn area type
|
|
215
|
+
*/
|
|
216
|
+
export type SpawnAreaType = 'point' | 'rect' | 'line' | 'circle';
|
|
217
|
+
/**
|
|
218
|
+
* Spawn area configuration (confettiSource equivalent)
|
|
219
|
+
*/
|
|
220
|
+
export interface SpawnArea {
|
|
221
|
+
/** Type of spawn area */
|
|
222
|
+
readonly type: SpawnAreaType;
|
|
223
|
+
/** X position of spawn area */
|
|
224
|
+
readonly x: number;
|
|
225
|
+
/** Y position of spawn area */
|
|
226
|
+
readonly y: number;
|
|
227
|
+
/** Width of spawn area (or radius for circle) */
|
|
228
|
+
readonly w?: number;
|
|
229
|
+
/** Height of spawn area */
|
|
230
|
+
readonly h?: number;
|
|
231
|
+
/** Legacy aliases */
|
|
232
|
+
readonly width?: number;
|
|
233
|
+
readonly height?: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Trail effect configuration
|
|
237
|
+
*/
|
|
238
|
+
export interface TrailConfig {
|
|
239
|
+
/** Enable trail effect. Default: false */
|
|
240
|
+
readonly enabled: boolean;
|
|
241
|
+
/** Trail length (number of positions to remember). Default: 10 */
|
|
242
|
+
readonly length: number;
|
|
243
|
+
/** Trail fade factor (0-1). Default: 0.5 */
|
|
244
|
+
readonly fade: number;
|
|
245
|
+
/** Trail width multiplier. Default: 0.5 */
|
|
246
|
+
readonly width: number;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Glow effect configuration
|
|
250
|
+
*/
|
|
251
|
+
export interface GlowConfig {
|
|
252
|
+
/** Enable glow effect. Default: false */
|
|
253
|
+
readonly enabled: boolean;
|
|
254
|
+
/** Glow blur radius. Default: 10 */
|
|
255
|
+
readonly blur: number;
|
|
256
|
+
/** Glow color (null = use particle color). Default: null */
|
|
257
|
+
readonly color: string | null;
|
|
258
|
+
/** Glow intensity (0-1). Default: 0.5 */
|
|
259
|
+
readonly intensity: number;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Image/Emoji particle configuration
|
|
263
|
+
*/
|
|
264
|
+
export interface ImageParticle {
|
|
265
|
+
/** Image source URL or emoji string */
|
|
266
|
+
readonly src: string;
|
|
267
|
+
/** Whether this is an emoji (true) or image URL (false) */
|
|
268
|
+
readonly isEmoji: boolean;
|
|
269
|
+
/** Scale factor for the image. Default: 1 */
|
|
270
|
+
readonly scale?: number;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Configuration for individual particles
|
|
274
|
+
*/
|
|
275
|
+
export interface ParticleConfig {
|
|
276
|
+
/** Array of colors for particles. Default: rainbow palette */
|
|
277
|
+
readonly colors: readonly ColorInput[];
|
|
278
|
+
/** Particle shapes to use. Default: ['square', 'circle'] */
|
|
279
|
+
readonly shapes: readonly ParticleShape[];
|
|
280
|
+
/** Size range [min, max] in pixels. Default: [8, 12] */
|
|
281
|
+
readonly size: readonly [number, number];
|
|
282
|
+
/** Opacity range [min, max]. Default: [0.8, 1] */
|
|
283
|
+
readonly opacity: readonly [number, number];
|
|
284
|
+
/** Lifespan in milliseconds. Default: 3000 */
|
|
285
|
+
readonly lifespan: number;
|
|
286
|
+
/** Whether to fade out particles. Default: true */
|
|
287
|
+
readonly fadeOut: boolean;
|
|
288
|
+
/** Whether to scale down particles over time. Default: true */
|
|
289
|
+
readonly scaleDown: boolean;
|
|
290
|
+
/** Custom draw function for 'custom' shape */
|
|
291
|
+
readonly drawShape?: CustomDrawFunction;
|
|
292
|
+
/** Image/emoji particles (overrides shapes if provided) */
|
|
293
|
+
readonly images?: readonly ImageParticle[];
|
|
294
|
+
/** Trail effect configuration */
|
|
295
|
+
readonly trail?: Partial<TrailConfig>;
|
|
296
|
+
/** Glow effect configuration */
|
|
297
|
+
readonly glow?: Partial<GlowConfig>;
|
|
298
|
+
/** Whether particles should spin. Default: true */
|
|
299
|
+
readonly spin: boolean;
|
|
300
|
+
/** Spin speed range [min, max]. Default: [-10, 10] */
|
|
301
|
+
readonly spinSpeed: readonly [number, number];
|
|
302
|
+
/** Tilt range in degrees [min, max]. Default: [-15, 15] */
|
|
303
|
+
readonly tilt: readonly [number, number];
|
|
304
|
+
/** 3D depth effect (0 = flat, 1 = full 3D). Default: 0 */
|
|
305
|
+
readonly depth3D: number;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Continuous mode configuration
|
|
309
|
+
*/
|
|
310
|
+
export interface ContinuousConfig {
|
|
311
|
+
/** Whether to recycle particles (continuous mode). Default: false */
|
|
312
|
+
readonly recycle: boolean;
|
|
313
|
+
/** Number of particles to maintain. Default: 200 */
|
|
314
|
+
readonly numberOfPieces: number;
|
|
315
|
+
/** Spawn rate (particles per second). Default: 50 */
|
|
316
|
+
readonly spawnRate: number;
|
|
317
|
+
/** Whether animation is running. Default: true */
|
|
318
|
+
readonly run: boolean;
|
|
319
|
+
/** Duration to add particles (tween duration). Default: 5000 */
|
|
320
|
+
readonly tweenDuration: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Firework mode configuration
|
|
324
|
+
*/
|
|
325
|
+
export interface FireworkConfig {
|
|
326
|
+
/** Enable secondary explosions. Default: true */
|
|
327
|
+
readonly secondaryExplosions: boolean;
|
|
328
|
+
/** Number of particles per burst. Default: 80 */
|
|
329
|
+
readonly burstCount: number;
|
|
330
|
+
/** Delay between fireworks (ms). Default: 500 */
|
|
331
|
+
readonly burstDelay: number;
|
|
332
|
+
/** Spread angle in degrees. Default: 360 */
|
|
333
|
+
readonly spread: number;
|
|
334
|
+
/** Height at which to explode (0-1 ratio of viewport). Default: 0.6 */
|
|
335
|
+
readonly launchHeight: number;
|
|
336
|
+
/** Rocket colors */
|
|
337
|
+
readonly rocketColors: readonly string[];
|
|
338
|
+
/** Burst colors */
|
|
339
|
+
readonly burstColors: readonly string[];
|
|
340
|
+
/** Trail length for particles */
|
|
341
|
+
readonly trailLength: number;
|
|
342
|
+
/** Rise duration in ms. Default: 1000 */
|
|
343
|
+
readonly riseDuration: number;
|
|
344
|
+
/** Show rocket trail. Default: true */
|
|
345
|
+
readonly showRocket: boolean;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Canvas configuration
|
|
349
|
+
*/
|
|
350
|
+
export interface CanvasConfig {
|
|
351
|
+
/** Canvas width (null = auto/viewport). Default: null */
|
|
352
|
+
readonly width: number | null;
|
|
353
|
+
/** Canvas height (null = auto/viewport). Default: null */
|
|
354
|
+
readonly height: number | null;
|
|
355
|
+
/** Auto-resize on window resize. Default: true */
|
|
356
|
+
readonly autoResize: boolean;
|
|
357
|
+
/** Resize debounce delay (ms). Default: 100 */
|
|
358
|
+
readonly resizeDebounce: number;
|
|
359
|
+
/** Frame rate cap (null = uncapped/60fps). Default: null */
|
|
360
|
+
readonly frameRate: number | null;
|
|
361
|
+
/** Device pixel ratio override (null = auto). Default: null */
|
|
362
|
+
readonly pixelRatio: number | null;
|
|
363
|
+
/** Canvas CSS class name */
|
|
364
|
+
readonly className?: string;
|
|
365
|
+
/** Canvas inline styles */
|
|
366
|
+
readonly style?: React.CSSProperties;
|
|
367
|
+
/** Use Web Worker for rendering (off main thread). Default: false */
|
|
368
|
+
readonly useWorker: boolean;
|
|
369
|
+
/** Use OffscreenCanvas if available. Default: false */
|
|
370
|
+
readonly useOffscreen: boolean;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Accessibility configuration
|
|
374
|
+
*/
|
|
375
|
+
export interface AccessibilityConfig {
|
|
376
|
+
/** Disable confetti for users who prefer reduced motion. Default: false */
|
|
377
|
+
readonly disableForReducedMotion: boolean;
|
|
378
|
+
/** ARIA label for the canvas. Default: 'Confetti animation' */
|
|
379
|
+
readonly ariaLabel?: string;
|
|
380
|
+
/** Whether to hide from screen readers. Default: true */
|
|
381
|
+
readonly ariaHidden: boolean;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* canvas-confetti compatible options
|
|
385
|
+
* These match the API of canvas-confetti for easy migration
|
|
386
|
+
*/
|
|
387
|
+
export interface CanvasConfettiOptions {
|
|
388
|
+
/** Number of confetti to launch. Default: 50 */
|
|
389
|
+
readonly particleCount?: number;
|
|
390
|
+
/** Angle to launch confetti in degrees (90 = straight up). Default: 90 */
|
|
391
|
+
readonly angle?: number;
|
|
392
|
+
/** Spread angle in degrees. Default: 45 */
|
|
393
|
+
readonly spread?: number;
|
|
394
|
+
/** Initial velocity in pixels. Default: 45 */
|
|
395
|
+
readonly startVelocity?: number;
|
|
396
|
+
/** Speed decay factor (0-1). Default: 0.9 */
|
|
397
|
+
readonly decay?: number;
|
|
398
|
+
/** Gravity (1 = full, 0 = none). Default: 1 */
|
|
399
|
+
readonly gravity?: number;
|
|
400
|
+
/** Horizontal drift (-1 to 1). Default: 0 */
|
|
401
|
+
readonly drift?: number;
|
|
402
|
+
/** Disable 3D tilt/wobble (2D mode). Default: false */
|
|
403
|
+
readonly flat?: boolean;
|
|
404
|
+
/** Number of animation frames. Default: 200 */
|
|
405
|
+
readonly ticks?: number;
|
|
406
|
+
/** Origin position (0-1 coordinates) */
|
|
407
|
+
readonly origin?: NormalizedOrigin;
|
|
408
|
+
/** Colors in hex format */
|
|
409
|
+
readonly colors?: readonly string[];
|
|
410
|
+
/** Shapes (strings or custom shape objects) */
|
|
411
|
+
readonly shapes?: readonly ShapeInput[];
|
|
412
|
+
/** Scale factor for particles. Default: 1 */
|
|
413
|
+
readonly scalar?: number;
|
|
414
|
+
/** Z-index for canvas. Default: 100 */
|
|
415
|
+
readonly zIndex?: number;
|
|
416
|
+
/** Disable for reduced motion preference. Default: false */
|
|
417
|
+
readonly disableForReducedMotion?: boolean;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Global options for confetti.create()
|
|
421
|
+
*/
|
|
422
|
+
export interface ConfettiCreateOptions {
|
|
423
|
+
/** Whether to resize canvas with window. Default: false */
|
|
424
|
+
readonly resize?: boolean;
|
|
425
|
+
/** Whether to use Web Worker for rendering. Default: false */
|
|
426
|
+
readonly useWorker?: boolean;
|
|
427
|
+
/** Disable for reduced motion users. Default: false */
|
|
428
|
+
readonly disableForReducedMotion?: boolean;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Main configuration for the confetti burst
|
|
432
|
+
*/
|
|
433
|
+
export interface ConfettiBurstConfig {
|
|
434
|
+
/** Number of particles to emit. Default: 50 */
|
|
435
|
+
readonly particleCount: number;
|
|
436
|
+
/** Particle configuration */
|
|
437
|
+
readonly particle: ParticleConfig;
|
|
438
|
+
/** Physics configuration */
|
|
439
|
+
readonly physics: PhysicsConfig;
|
|
440
|
+
/** Direction configuration */
|
|
441
|
+
readonly direction: DirectionConfig;
|
|
442
|
+
/** Effect mode. Default: 'burst' */
|
|
443
|
+
readonly mode: EffectMode;
|
|
444
|
+
/** Spawn area configuration */
|
|
445
|
+
readonly spawnArea?: SpawnArea;
|
|
446
|
+
/** Continuous mode configuration */
|
|
447
|
+
readonly continuous?: Partial<ContinuousConfig>;
|
|
448
|
+
/** Firework mode configuration */
|
|
449
|
+
readonly firework?: Partial<FireworkConfig>;
|
|
450
|
+
/** Canvas configuration */
|
|
451
|
+
readonly canvas?: Partial<CanvasConfig>;
|
|
452
|
+
/** Accessibility configuration */
|
|
453
|
+
readonly accessibility?: Partial<AccessibilityConfig>;
|
|
454
|
+
/** Easing preset for animation. Default: 'easeOut' */
|
|
455
|
+
readonly easing: EasingPreset;
|
|
456
|
+
/** Z-index for the canvas overlay. Default: 9999 */
|
|
457
|
+
readonly zIndex: number;
|
|
458
|
+
/** Whether to auto-clean canvas when animation ends. Default: true */
|
|
459
|
+
readonly autoCleanup: boolean;
|
|
460
|
+
/** Global scale factor for all particles. Default: 1 */
|
|
461
|
+
readonly scalar: number;
|
|
462
|
+
/** Horizontal drift factor (-1 to 1). Default: 0 */
|
|
463
|
+
readonly drift: number;
|
|
464
|
+
/** Number of animation frames/ticks. Overrides lifespan if set */
|
|
465
|
+
readonly ticks?: number;
|
|
466
|
+
/** Disable 3D tilt/wobble effects (2D mode). Default: false */
|
|
467
|
+
readonly flat: boolean;
|
|
468
|
+
/** Callback when animation starts */
|
|
469
|
+
readonly onStart?: () => void;
|
|
470
|
+
/** Callback when animation ends */
|
|
471
|
+
readonly onComplete?: () => void;
|
|
472
|
+
/** Callback on each frame with particle count */
|
|
473
|
+
readonly onFrame?: (particleCount: number) => void;
|
|
474
|
+
/** Callback when a particle is created */
|
|
475
|
+
readonly onParticleCreate?: (particle: ParticleState) => void;
|
|
476
|
+
/** Callback when a particle dies */
|
|
477
|
+
readonly onParticleDeath?: (particle: ParticleState) => void;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Partial configuration allowing users to override specific options
|
|
481
|
+
*/
|
|
482
|
+
export type ConfettiBurstOptions = Partial<{
|
|
483
|
+
readonly particleCount: number;
|
|
484
|
+
readonly particle: Partial<ParticleConfig>;
|
|
485
|
+
readonly physics: Partial<PhysicsConfig>;
|
|
486
|
+
readonly direction: Partial<DirectionConfig>;
|
|
487
|
+
readonly mode: EffectMode;
|
|
488
|
+
readonly spawnArea: Partial<SpawnArea>;
|
|
489
|
+
readonly continuous: Partial<ContinuousConfig>;
|
|
490
|
+
readonly firework: Partial<FireworkConfig>;
|
|
491
|
+
readonly canvas: Partial<CanvasConfig>;
|
|
492
|
+
readonly accessibility: Partial<AccessibilityConfig>;
|
|
493
|
+
readonly easing: EasingPreset;
|
|
494
|
+
readonly zIndex: number;
|
|
495
|
+
readonly autoCleanup: boolean;
|
|
496
|
+
readonly scalar: number;
|
|
497
|
+
readonly drift: number;
|
|
498
|
+
readonly ticks: number;
|
|
499
|
+
readonly flat: boolean;
|
|
500
|
+
readonly onStart: () => void;
|
|
501
|
+
readonly onComplete: () => void;
|
|
502
|
+
readonly onFrame: (particleCount: number) => void;
|
|
503
|
+
readonly onParticleCreate: (particle: ParticleState) => void;
|
|
504
|
+
readonly onParticleDeath: (particle: ParticleState) => void;
|
|
505
|
+
}>;
|
|
506
|
+
/**
|
|
507
|
+
* Origin point for the burst
|
|
508
|
+
*/
|
|
509
|
+
export interface BurstOrigin {
|
|
510
|
+
/** X coordinate (relative to viewport or element) */
|
|
511
|
+
readonly x: number;
|
|
512
|
+
/** Y coordinate (relative to viewport or element) */
|
|
513
|
+
readonly y: number;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Trail position for trail effect
|
|
517
|
+
*/
|
|
518
|
+
export interface TrailPosition {
|
|
519
|
+
x: number;
|
|
520
|
+
y: number;
|
|
521
|
+
opacity: number;
|
|
522
|
+
size: number;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Internal particle state
|
|
526
|
+
*/
|
|
527
|
+
export interface ParticleState {
|
|
528
|
+
id: number;
|
|
529
|
+
x: number;
|
|
530
|
+
y: number;
|
|
531
|
+
vx: number;
|
|
532
|
+
vy: number;
|
|
533
|
+
size: number;
|
|
534
|
+
originalSize: number;
|
|
535
|
+
rotation: number;
|
|
536
|
+
rotationSpeed: number;
|
|
537
|
+
color: RGBAColor;
|
|
538
|
+
shape: ParticleShape;
|
|
539
|
+
opacity: number;
|
|
540
|
+
originalOpacity: number;
|
|
541
|
+
life: number;
|
|
542
|
+
maxLife: number;
|
|
543
|
+
active: boolean;
|
|
544
|
+
/** Image/emoji source if using image particles */
|
|
545
|
+
image?: ImageParticle;
|
|
546
|
+
/** Loaded image element for image particles */
|
|
547
|
+
imageElement?: HTMLImageElement | null;
|
|
548
|
+
/** Trail positions for trail effect */
|
|
549
|
+
trail: TrailPosition[];
|
|
550
|
+
/** Wobble phase for 3D effect */
|
|
551
|
+
wobblePhase: number;
|
|
552
|
+
/** Wobble speed for 3D effect */
|
|
553
|
+
wobbleSpeed: number;
|
|
554
|
+
/** Tilt angle in radians */
|
|
555
|
+
tilt: number;
|
|
556
|
+
/** Tilt speed */
|
|
557
|
+
tiltSpeed: number;
|
|
558
|
+
/** 3D depth factor */
|
|
559
|
+
depth: number;
|
|
560
|
+
/** Whether this particle has exploded (firework mode) */
|
|
561
|
+
hasExploded: boolean;
|
|
562
|
+
/** Custom data storage */
|
|
563
|
+
data: Record<string, unknown>;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Animation frame state
|
|
567
|
+
*/
|
|
568
|
+
export interface AnimationState {
|
|
569
|
+
readonly isRunning: boolean;
|
|
570
|
+
readonly isPaused: boolean;
|
|
571
|
+
readonly frameId: number | null;
|
|
572
|
+
readonly startTime: number | null;
|
|
573
|
+
readonly lastFrameTime: number;
|
|
574
|
+
readonly particles: ParticleState[];
|
|
575
|
+
readonly particleCount: number;
|
|
576
|
+
readonly elapsedTime: number;
|
|
577
|
+
readonly fps: number;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Canvas context wrapper for type safety
|
|
581
|
+
*/
|
|
582
|
+
export interface CanvasContext {
|
|
583
|
+
readonly canvas: HTMLCanvasElement;
|
|
584
|
+
readonly ctx: CanvasRenderingContext2D;
|
|
585
|
+
readonly width: number;
|
|
586
|
+
readonly height: number;
|
|
587
|
+
readonly dpr: number;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Result from the explosion trigger function
|
|
591
|
+
*/
|
|
592
|
+
export interface ExplosionHandle {
|
|
593
|
+
/** Stop the animation immediately */
|
|
594
|
+
readonly stop: () => void;
|
|
595
|
+
/** Pause the animation */
|
|
596
|
+
readonly pause: () => void;
|
|
597
|
+
/** Resume a paused animation */
|
|
598
|
+
readonly resume: () => void;
|
|
599
|
+
/** Add more particles to running animation */
|
|
600
|
+
readonly addParticles: (count: number) => void;
|
|
601
|
+
/** Clear all particles immediately */
|
|
602
|
+
readonly clear: () => void;
|
|
603
|
+
/** Get current particle count */
|
|
604
|
+
readonly getParticleCount: () => number;
|
|
605
|
+
/** Get animation state */
|
|
606
|
+
readonly getState: () => 'running' | 'paused' | 'stopped';
|
|
607
|
+
/** Promise that resolves when animation completes */
|
|
608
|
+
readonly promise: Promise<void>;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Hook return type for useConfetti
|
|
612
|
+
*/
|
|
613
|
+
export interface UseConfettiReturn {
|
|
614
|
+
/** Trigger confetti from a point */
|
|
615
|
+
readonly fire: (origin: BurstOrigin, options?: ConfettiBurstOptions) => ExplosionHandle;
|
|
616
|
+
/** Trigger confetti from an element */
|
|
617
|
+
readonly fireFromElement: (element: HTMLElement | null, options?: ConfettiBurstOptions) => ExplosionHandle | null;
|
|
618
|
+
/** Check if animation is currently running */
|
|
619
|
+
readonly isActive: boolean;
|
|
620
|
+
/** Stop all active animations */
|
|
621
|
+
readonly stopAll: () => void;
|
|
622
|
+
/** Pause all active animations */
|
|
623
|
+
readonly pauseAll: () => void;
|
|
624
|
+
/** Resume all paused animations */
|
|
625
|
+
readonly resumeAll: () => void;
|
|
626
|
+
/** Get all active handles */
|
|
627
|
+
readonly getActiveHandles: () => ExplosionHandle[];
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Props for the ConfettiBurst component
|
|
631
|
+
*/
|
|
632
|
+
export interface ConfettiBurstProps {
|
|
633
|
+
/** Whether the confetti should be triggered */
|
|
634
|
+
readonly active: boolean;
|
|
635
|
+
/** Origin point for the burst */
|
|
636
|
+
readonly origin?: BurstOrigin;
|
|
637
|
+
/** Reference to the trigger element (alternative to origin) */
|
|
638
|
+
readonly triggerRef?: React.RefObject<HTMLElement>;
|
|
639
|
+
/** Configuration options */
|
|
640
|
+
readonly options?: ConfettiBurstOptions;
|
|
641
|
+
/** Callback when animation completes */
|
|
642
|
+
readonly onComplete?: () => void;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Props for the ConfettiButton component
|
|
646
|
+
*/
|
|
647
|
+
export interface ConfettiButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
648
|
+
/** Configuration options */
|
|
649
|
+
readonly confettiOptions?: ConfettiBurstOptions;
|
|
650
|
+
/** Whether to fire on click. Default: true */
|
|
651
|
+
readonly fireOnClick?: boolean;
|
|
652
|
+
/** Children elements */
|
|
653
|
+
readonly children: React.ReactNode;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Props for the Confetti component (react-confetti compatible API)
|
|
657
|
+
*/
|
|
658
|
+
export interface ConfettiProps {
|
|
659
|
+
/** Canvas width */
|
|
660
|
+
readonly width?: number;
|
|
661
|
+
/** Canvas height */
|
|
662
|
+
readonly height?: number;
|
|
663
|
+
/** Number of confetti pieces at one time */
|
|
664
|
+
readonly numberOfPieces?: number;
|
|
665
|
+
/** Rectangle where confetti should spawn */
|
|
666
|
+
readonly confettiSource?: SpawnArea;
|
|
667
|
+
/** Friction coefficient */
|
|
668
|
+
readonly friction?: number;
|
|
669
|
+
/** Wind force */
|
|
670
|
+
readonly wind?: number;
|
|
671
|
+
/** Gravity strength */
|
|
672
|
+
readonly gravity?: number;
|
|
673
|
+
/** Initial horizontal velocity */
|
|
674
|
+
readonly initialVelocityX?: number | {
|
|
675
|
+
min: number;
|
|
676
|
+
max: number;
|
|
677
|
+
};
|
|
678
|
+
/** Initial vertical velocity */
|
|
679
|
+
readonly initialVelocityY?: number | {
|
|
680
|
+
min: number;
|
|
681
|
+
max: number;
|
|
682
|
+
};
|
|
683
|
+
/** Colors array */
|
|
684
|
+
readonly colors?: string[];
|
|
685
|
+
/** Opacity */
|
|
686
|
+
readonly opacity?: number;
|
|
687
|
+
/** Keep spawning confetti */
|
|
688
|
+
readonly recycle?: boolean;
|
|
689
|
+
/** Run the animation */
|
|
690
|
+
readonly run?: boolean;
|
|
691
|
+
/** Frame rate cap */
|
|
692
|
+
readonly frameRate?: number;
|
|
693
|
+
/** Tween duration */
|
|
694
|
+
readonly tweenDuration?: number;
|
|
695
|
+
/** Tween function */
|
|
696
|
+
readonly tweenFunction?: EasingFunction;
|
|
697
|
+
/** Custom draw function */
|
|
698
|
+
readonly drawShape?: (ctx: CanvasRenderingContext2D) => void;
|
|
699
|
+
/** Callback when all confetti has fallen */
|
|
700
|
+
readonly onConfettiComplete?: () => void;
|
|
701
|
+
/** Canvas ref */
|
|
702
|
+
readonly canvasRef?: React.RefObject<HTMLCanvasElement>;
|
|
703
|
+
/** Canvas class name */
|
|
704
|
+
readonly className?: string;
|
|
705
|
+
/** Canvas style */
|
|
706
|
+
readonly style?: React.CSSProperties;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Preset configuration names
|
|
710
|
+
*/
|
|
711
|
+
export type PresetName = 'default' | 'celebration' | 'firework' | 'snow' | 'rain' | 'sparkle' | 'confetti' | 'emoji' | 'hearts' | 'stars' | 'money' | 'pride' | 'christmas' | 'halloween' | 'newYear' | 'birthday';
|
|
712
|
+
/**
|
|
713
|
+
* Preset configuration
|
|
714
|
+
*/
|
|
715
|
+
export interface PresetConfig {
|
|
716
|
+
readonly name: PresetName;
|
|
717
|
+
readonly options: ConfettiBurstOptions;
|
|
718
|
+
readonly description: string;
|
|
719
|
+
}
|
|
720
|
+
//# sourceMappingURL=types.d.ts.map
|