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,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React components for confetti animations
|
|
3
|
+
*
|
|
4
|
+
* Provides declarative components for easy integration of confetti
|
|
5
|
+
* effects into React applications.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { ConfettiBurstProps, ConfettiButtonProps, ExplosionHandle, BurstOrigin } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Declarative confetti component that fires when active prop changes
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const [celebrate, setCelebrate] = useState(false);
|
|
15
|
+
*
|
|
16
|
+
* return (
|
|
17
|
+
* <>
|
|
18
|
+
* <ConfettiBurst
|
|
19
|
+
* active={celebrate}
|
|
20
|
+
* origin={{ x: 500, y: 300 }}
|
|
21
|
+
* onComplete={() => setCelebrate(false)}
|
|
22
|
+
* />
|
|
23
|
+
* <button onClick={() => setCelebrate(true)}>
|
|
24
|
+
* Celebrate!
|
|
25
|
+
* </button>
|
|
26
|
+
* </>
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function ConfettiBurst({ active, origin, triggerRef, options, onComplete, }: ConfettiBurstProps): null;
|
|
31
|
+
/**
|
|
32
|
+
* Handle type for ConfettiTrigger ref
|
|
33
|
+
*/
|
|
34
|
+
export interface ConfettiTriggerHandle {
|
|
35
|
+
fire: () => ExplosionHandle | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Invisible trigger component that fires confetti from its position
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* const triggerRef = useRef<ConfettiTriggerHandle>(null);
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <div style={{ position: 'relative' }}>
|
|
46
|
+
* <ConfettiTrigger ref={triggerRef} options={{ particleCount: 100 }} />
|
|
47
|
+
* <button onClick={() => triggerRef.current?.fire()}>
|
|
48
|
+
* Fire!
|
|
49
|
+
* </button>
|
|
50
|
+
* </div>
|
|
51
|
+
* );
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const ConfettiTrigger: React.ForwardRefExoticComponent<{
|
|
55
|
+
options?: ConfettiBurstProps["options"];
|
|
56
|
+
style?: React.CSSProperties;
|
|
57
|
+
} & React.RefAttributes<ConfettiTriggerHandle>>;
|
|
58
|
+
/**
|
|
59
|
+
* Button component that automatically fires confetti on click
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* <ConfettiButton
|
|
64
|
+
* confettiOptions={{
|
|
65
|
+
* particleCount: 30,
|
|
66
|
+
* direction: { direction: 'up' }
|
|
67
|
+
* }}
|
|
68
|
+
* >
|
|
69
|
+
* Submit
|
|
70
|
+
* </ConfettiButton>
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const ConfettiButton: React.ForwardRefExoticComponent<ConfettiButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
74
|
+
/**
|
|
75
|
+
* Props for ConfettiOnMount component
|
|
76
|
+
*/
|
|
77
|
+
interface ConfettiOnMountProps {
|
|
78
|
+
origin?: BurstOrigin;
|
|
79
|
+
options?: ConfettiBurstProps['options'];
|
|
80
|
+
onComplete?: () => void;
|
|
81
|
+
delay?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Component that fires confetti when mounted
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* // Fire confetti when a success page loads
|
|
89
|
+
* function SuccessPage() {
|
|
90
|
+
* return (
|
|
91
|
+
* <div>
|
|
92
|
+
* <ConfettiOnMount
|
|
93
|
+
* origin={{ x: window.innerWidth / 2, y: window.innerHeight / 3 }}
|
|
94
|
+
* options={{ particleCount: 100 }}
|
|
95
|
+
* />
|
|
96
|
+
* <h1>Success!</h1>
|
|
97
|
+
* </div>
|
|
98
|
+
* );
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function ConfettiOnMount({ origin, options, onComplete, delay, }: ConfettiOnMountProps): null;
|
|
103
|
+
/**
|
|
104
|
+
* Props for ConfettiCannon component
|
|
105
|
+
*/
|
|
106
|
+
interface ConfettiCannonProps {
|
|
107
|
+
/** Position from left (percentage or pixels) */
|
|
108
|
+
left?: number | string;
|
|
109
|
+
/** Position from top (percentage or pixels) */
|
|
110
|
+
top?: number | string;
|
|
111
|
+
/** Angle in degrees (0 = right, 90 = up) */
|
|
112
|
+
angle?: number;
|
|
113
|
+
/** Confetti options */
|
|
114
|
+
options?: ConfettiBurstProps['options'];
|
|
115
|
+
/** When true, fires the cannon */
|
|
116
|
+
fire?: boolean;
|
|
117
|
+
/** Callback when animation completes */
|
|
118
|
+
onComplete?: () => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Positioned cannon component for directional confetti bursts
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* <ConfettiCannon
|
|
126
|
+
* left="10%"
|
|
127
|
+
* top="80%"
|
|
128
|
+
* angle={60}
|
|
129
|
+
* fire={shouldFire}
|
|
130
|
+
* options={{ particleCount: 50 }}
|
|
131
|
+
* />
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function ConfettiCannon({ left, top, angle, options, fire: shouldFire, onComplete, }: ConfettiCannonProps): null;
|
|
135
|
+
/**
|
|
136
|
+
* React-confetti compatible Confetti component
|
|
137
|
+
*
|
|
138
|
+
* This component provides a drop-in replacement for react-confetti
|
|
139
|
+
* with continuous confetti that falls from the top of the screen.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```tsx
|
|
143
|
+
* // Basic usage - continuous confetti
|
|
144
|
+
* <Confetti />
|
|
145
|
+
*
|
|
146
|
+
* // With options
|
|
147
|
+
* <Confetti
|
|
148
|
+
* width={window.innerWidth}
|
|
149
|
+
* height={window.innerHeight}
|
|
150
|
+
* numberOfPieces={200}
|
|
151
|
+
* recycle={true}
|
|
152
|
+
* run={true}
|
|
153
|
+
* />
|
|
154
|
+
*
|
|
155
|
+
* // With custom draw function
|
|
156
|
+
* <Confetti
|
|
157
|
+
* drawShape={ctx => {
|
|
158
|
+
* ctx.beginPath();
|
|
159
|
+
* ctx.arc(0, 0, 5, 0, Math.PI * 2);
|
|
160
|
+
* ctx.fill();
|
|
161
|
+
* }}
|
|
162
|
+
* />
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export interface ConfettiComponentProps {
|
|
166
|
+
/** Width of the canvas in pixels (default: window.innerWidth) */
|
|
167
|
+
width?: number;
|
|
168
|
+
/** Height of the canvas in pixels (default: window.innerHeight) */
|
|
169
|
+
height?: number;
|
|
170
|
+
/** Number of confetti pieces (default: 200) */
|
|
171
|
+
numberOfPieces?: number;
|
|
172
|
+
/** Spawn area for confetti pieces */
|
|
173
|
+
confettiSource?: {
|
|
174
|
+
x: number;
|
|
175
|
+
y: number;
|
|
176
|
+
w?: number;
|
|
177
|
+
h?: number;
|
|
178
|
+
};
|
|
179
|
+
/** Initial horizontal velocity range (default: [4, 10]) */
|
|
180
|
+
initialVelocityX?: number | {
|
|
181
|
+
min: number;
|
|
182
|
+
max: number;
|
|
183
|
+
};
|
|
184
|
+
/** Initial vertical velocity range (default: [10, 30]) */
|
|
185
|
+
initialVelocityY?: number | {
|
|
186
|
+
min: number;
|
|
187
|
+
max: number;
|
|
188
|
+
};
|
|
189
|
+
/** Whether to recycle confetti (default: true) */
|
|
190
|
+
recycle?: boolean;
|
|
191
|
+
/** Whether the animation is running (default: true) */
|
|
192
|
+
run?: boolean;
|
|
193
|
+
/** Gravity value (default: 0.3) */
|
|
194
|
+
gravity?: number;
|
|
195
|
+
/** Wind value (default: 0) */
|
|
196
|
+
wind?: number;
|
|
197
|
+
/** Opacity of confetti pieces (0-1, default: 1) */
|
|
198
|
+
opacity?: number;
|
|
199
|
+
/** Custom draw function */
|
|
200
|
+
drawShape?: (ctx: CanvasRenderingContext2D) => void;
|
|
201
|
+
/** Tween duration when recycle changes (ms) */
|
|
202
|
+
tweenDuration?: number;
|
|
203
|
+
/** Array of colors */
|
|
204
|
+
colors?: string[];
|
|
205
|
+
/** Callback when confetti is created */
|
|
206
|
+
onConfettiComplete?: (confetti: any) => void;
|
|
207
|
+
/** Frame rate limit */
|
|
208
|
+
frameRate?: number;
|
|
209
|
+
/** Z-index of the canvas */
|
|
210
|
+
style?: React.CSSProperties;
|
|
211
|
+
/** Class name for the canvas */
|
|
212
|
+
className?: string;
|
|
213
|
+
}
|
|
214
|
+
export declare function Confetti({ width, height, numberOfPieces, confettiSource, initialVelocityX, initialVelocityY, recycle, run, gravity, wind, opacity, drawShape, tweenDuration, colors, onConfettiComplete, frameRate, }: ConfettiComponentProps): null;
|
|
215
|
+
export declare namespace Confetti {
|
|
216
|
+
var displayName: string;
|
|
217
|
+
}
|
|
218
|
+
export {};
|
|
219
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/components.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAMN,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,MAAM,EACN,UAAU,EACV,OAAO,EACP,UAAU,GACX,EAAE,kBAAkB,GAAG,IAAI,CAgC3B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,eAAe,GAAG,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe;cAGd,kBAAkB,CAAC,SAAS,CAAC;YAC/B,KAAK,CAAC,aAAa;+CAuB7B,CAAC;AAIH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,+FA4C1B,CAAC;AAIF;;GAEG;AACH,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC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H/B;yBA9Ie,QAAQ"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confetti Engine - Core Canvas-based animation system
|
|
3
|
+
*
|
|
4
|
+
* This module provides the main confetti animation engine that manages
|
|
5
|
+
* particle creation, physics updates, and rendering using the Canvas API.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - High-performance requestAnimationFrame loop
|
|
9
|
+
* - Automatic DPR (Device Pixel Ratio) handling
|
|
10
|
+
* - Directional burst support
|
|
11
|
+
* - Continuous/recycle mode (like react-confetti)
|
|
12
|
+
* - Firework mode with secondary explosions
|
|
13
|
+
* - Spawn area support
|
|
14
|
+
* - Memory-efficient particle pooling
|
|
15
|
+
* - Automatic cleanup
|
|
16
|
+
*/
|
|
17
|
+
import type { ConfettiBurstOptions, BurstOrigin, ExplosionHandle } from './types';
|
|
18
|
+
/**
|
|
19
|
+
* Main confetti engine class
|
|
20
|
+
*/
|
|
21
|
+
export declare class ConfettiEngine {
|
|
22
|
+
private particles;
|
|
23
|
+
private config;
|
|
24
|
+
private origin;
|
|
25
|
+
private canvasContext;
|
|
26
|
+
private animationFrameId;
|
|
27
|
+
private lastFrameTime;
|
|
28
|
+
private lastSpawnTime;
|
|
29
|
+
private isRunning;
|
|
30
|
+
private isPaused;
|
|
31
|
+
private deferred;
|
|
32
|
+
private mode;
|
|
33
|
+
private spawnArea?;
|
|
34
|
+
private continuousConfig;
|
|
35
|
+
private fireworkConfig;
|
|
36
|
+
private canvasConfig;
|
|
37
|
+
private drawShape?;
|
|
38
|
+
private frameInterval;
|
|
39
|
+
private lastRenderTime;
|
|
40
|
+
constructor(origin: BurstOrigin, options?: ConfettiBurstOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Starts the confetti animation
|
|
43
|
+
*/
|
|
44
|
+
start(): ExplosionHandle;
|
|
45
|
+
/**
|
|
46
|
+
* Creates particles for the burst
|
|
47
|
+
*/
|
|
48
|
+
private createParticles;
|
|
49
|
+
/**
|
|
50
|
+
* Spawns particles for continuous mode
|
|
51
|
+
*/
|
|
52
|
+
private spawnParticles;
|
|
53
|
+
/**
|
|
54
|
+
* Launches a firework
|
|
55
|
+
*/
|
|
56
|
+
private launchFirework;
|
|
57
|
+
/**
|
|
58
|
+
* Triggers a firework explosion at a position
|
|
59
|
+
*/
|
|
60
|
+
private explodeFirework;
|
|
61
|
+
/**
|
|
62
|
+
* Main animation loop
|
|
63
|
+
*/
|
|
64
|
+
private animate;
|
|
65
|
+
/**
|
|
66
|
+
* Stops the animation immediately
|
|
67
|
+
*/
|
|
68
|
+
stop(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Pauses the animation
|
|
71
|
+
*/
|
|
72
|
+
pause(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Resumes a paused animation
|
|
75
|
+
*/
|
|
76
|
+
resume(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Called when animation completes naturally
|
|
79
|
+
*/
|
|
80
|
+
private complete;
|
|
81
|
+
/**
|
|
82
|
+
* Cleans up resources
|
|
83
|
+
*/
|
|
84
|
+
private cleanup;
|
|
85
|
+
/**
|
|
86
|
+
* Adds more particles to the animation
|
|
87
|
+
*/
|
|
88
|
+
addParticles(count: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Clears all particles
|
|
91
|
+
*/
|
|
92
|
+
clear(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Gets current particle count
|
|
95
|
+
*/
|
|
96
|
+
getParticleCount(): number;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the current state
|
|
99
|
+
*/
|
|
100
|
+
getState(): 'running' | 'paused' | 'stopped';
|
|
101
|
+
/**
|
|
102
|
+
* Creates the explosion handle for external control
|
|
103
|
+
*/
|
|
104
|
+
private createHandle;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates and starts a confetti explosion
|
|
108
|
+
*/
|
|
109
|
+
export declare function createConfettiExplosion(origin: BurstOrigin, options?: ConfettiBurstOptions): ExplosionHandle;
|
|
110
|
+
/**
|
|
111
|
+
* Fires confetti from an element's center
|
|
112
|
+
*/
|
|
113
|
+
export declare function fireFromElement(element: HTMLElement | null, options?: ConfettiBurstOptions): ExplosionHandle | null;
|
|
114
|
+
/**
|
|
115
|
+
* Gets the current number of active animations
|
|
116
|
+
*/
|
|
117
|
+
export declare function getActiveAnimationCount(): number;
|
|
118
|
+
/**
|
|
119
|
+
* Forces cleanup of all resources
|
|
120
|
+
*/
|
|
121
|
+
export declare function forceCleanup(): void;
|
|
122
|
+
//# sourceMappingURL=confetti-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confetti-engine.d.ts","sourceRoot":"","sources":["../../src/confetti-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAEV,oBAAoB,EACpB,WAAW,EAGX,eAAe,EAOhB,MAAM,SAAS,CAAC;AAoKjB;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,QAAQ,CAA0B;IAG1C,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,SAAS,CAAC,CAAqB;IACvC,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,cAAc,CAAa;gBAEvB,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,oBAAoB;IAkB/D;;OAEG;IACH,KAAK,IAAI,eAAe;IA6CxB;;OAEG;IACH,OAAO,CAAC,eAAe;IA+CvB;;OAEG;IACH,OAAO,CAAC,cAAc;IA0DtB;;OAEG;IACH,OAAO,CAAC,cAAc;IA4CtB;;OAEG;IACH,OAAO,CAAC,eAAe;IAgCvB;;OAEG;IACH,OAAO,CAAC,OAAO,CAkHb;IAEF;;OAEG;IACH,IAAI,IAAI,IAAI;IAYZ;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,CAAC,QAAQ;IAMhB;;OAEG;IACH,OAAO,CAAC,OAAO;IAaf;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAgCjC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAI1B;;OAEG;IACH,QAAQ,IAAI,SAAS,GAAG,QAAQ,GAAG,SAAS;IAM5C;;OAEG;IACH,OAAO,CAAC,YAAY;CAYrB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,eAAe,CAGjB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,WAAW,GAAG,IAAI,EAC3B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,eAAe,GAAG,IAAI,CAYxB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAOnC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functional Confetti API
|
|
3
|
+
*
|
|
4
|
+
* Provides a canvas-confetti compatible function-based API for
|
|
5
|
+
* imperative confetti control without React components.
|
|
6
|
+
*
|
|
7
|
+
* @module confetti
|
|
8
|
+
*/
|
|
9
|
+
import type { CanvasConfettiOptions, ConfettiCreateOptions } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Main confetti function - canvas-confetti compatible API
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Basic confetti burst
|
|
16
|
+
* confetti();
|
|
17
|
+
*
|
|
18
|
+
* // Customized confetti
|
|
19
|
+
* confetti({
|
|
20
|
+
* particleCount: 100,
|
|
21
|
+
* spread: 70,
|
|
22
|
+
* origin: { x: 0.5, y: 0.5 }
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Wait for completion
|
|
26
|
+
* await confetti({ particleCount: 200 });
|
|
27
|
+
* console.log('Confetti finished!');
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param options - Confetti configuration options
|
|
31
|
+
* @returns Promise that resolves when animation completes
|
|
32
|
+
*/
|
|
33
|
+
export declare function confetti(options?: CanvasConfettiOptions): Promise<void> | null;
|
|
34
|
+
export declare namespace confetti {
|
|
35
|
+
var create: (canvas: HTMLCanvasElement, globalOptions?: ConfettiCreateOptions) => ((options?: CanvasConfettiOptions) => Promise<void> | null) & {
|
|
36
|
+
reset: () => void;
|
|
37
|
+
};
|
|
38
|
+
var reset: () => void;
|
|
39
|
+
var fireworks: (options?: Partial<CanvasConfettiOptions>) => Promise<void>;
|
|
40
|
+
var schoolPride: (options?: Partial<CanvasConfettiOptions>) => void;
|
|
41
|
+
var snow: (options?: {
|
|
42
|
+
duration?: number;
|
|
43
|
+
} & Partial<CanvasConfettiOptions>) => void;
|
|
44
|
+
var burst: (origin: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}, options?: Partial<CanvasConfettiOptions>) => Promise<void> | null;
|
|
48
|
+
}
|
|
49
|
+
export default confetti;
|
|
50
|
+
//# sourceMappingURL=confetti.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confetti.d.ts","sourceRoot":"","sources":["../../src/confetti.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAmRjB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CA6BlF;yBA7Be,QAAQ;yBAoDd,iBAAiB,kBACV,qBAAqB,KACnC,CAAC,CAAC,OAAO,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG;QAAE,KAAK,EAAE,MAAM,IAAI,CAAA;KAAE;qBA+DzD,IAAI;8BAwBY,OAAO,CAAC,qBAAqB,CAAC,KAAQ,OAAO,CAAC,IAAI,CAAC;gCA8BvD,OAAO,CAAC,qBAAqB,CAAC,KAAQ,IAAI;yBAsCjD;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,KAAQ,IAAI;wBAsC1F;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,YACvB,OAAO,CAAC,qBAAqB,CAAC,KACtC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;;AAavB,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default constants and configuration values
|
|
3
|
+
*
|
|
4
|
+
* All default values are carefully tuned for optimal visual appeal
|
|
5
|
+
* and performance across different devices and screen sizes.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConfettiBurstConfig, ParticleConfig, PhysicsConfig, DirectionConfig, EasingFunction, EasingPreset, RGBAColor, ContinuousConfig, FireworkConfig, CanvasConfig, TrailConfig, GlowConfig, PresetConfig, PresetName, ConfettiBurstOptions } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Default vibrant color palette for confetti particles
|
|
10
|
+
* Designed for high visibility on both light and dark backgrounds
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_COLORS: readonly string[];
|
|
13
|
+
/**
|
|
14
|
+
* Default physics configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_PHYSICS: PhysicsConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Default direction configuration
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_DIRECTION: DirectionConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Default particle configuration
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_PARTICLE: ParticleConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Default trail configuration
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_TRAIL: TrailConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Default glow configuration
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_GLOW: GlowConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Default continuous mode configuration
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_CONTINUOUS: ContinuousConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Default firework configuration
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_FIREWORK: FireworkConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Default canvas configuration
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_CANVAS: CanvasConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Default accessibility configuration
|
|
47
|
+
*/
|
|
48
|
+
export declare const DEFAULT_ACCESSIBILITY: {
|
|
49
|
+
readonly disableForReducedMotion: false;
|
|
50
|
+
readonly ariaLabel: "Confetti animation";
|
|
51
|
+
readonly ariaHidden: true;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Complete default configuration
|
|
55
|
+
*/
|
|
56
|
+
export declare const DEFAULT_CONFIG: ConfettiBurstConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Direction angles in degrees (0 = right, counter-clockwise)
|
|
59
|
+
*/
|
|
60
|
+
export declare const DIRECTION_ANGLES: Record<Exclude<import('./types').BurstDirection, 'custom' | 'radial'>, number>;
|
|
61
|
+
/**
|
|
62
|
+
* Pre-calculated values for performance
|
|
63
|
+
*/
|
|
64
|
+
export declare const MATH_CONSTANTS: {
|
|
65
|
+
readonly DEG_TO_RAD: number;
|
|
66
|
+
readonly RAD_TO_DEG: number;
|
|
67
|
+
readonly TWO_PI: number;
|
|
68
|
+
readonly HALF_PI: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Easing functions for smooth animations
|
|
72
|
+
*/
|
|
73
|
+
export declare const EASING_FUNCTIONS: Record<EasingPreset, EasingFunction>;
|
|
74
|
+
/**
|
|
75
|
+
* Built-in shape names (excluding custom shapes)
|
|
76
|
+
*/
|
|
77
|
+
type BuiltinShapeName = 'square' | 'circle' | 'rectangle' | 'triangle' | 'star' | 'line' | 'heart' | 'diamond' | 'hexagon' | 'spiral' | 'ribbon' | 'custom';
|
|
78
|
+
/**
|
|
79
|
+
* Shape rendering aspect ratios
|
|
80
|
+
*/
|
|
81
|
+
export declare const SHAPE_ASPECT_RATIOS: Record<BuiltinShapeName, number>;
|
|
82
|
+
/**
|
|
83
|
+
* Default transparent color for fallback
|
|
84
|
+
*/
|
|
85
|
+
export declare const TRANSPARENT_COLOR: RGBAColor;
|
|
86
|
+
/**
|
|
87
|
+
* Performance tuning constants
|
|
88
|
+
*/
|
|
89
|
+
export declare const PERFORMANCE: {
|
|
90
|
+
/** Maximum particles before reducing quality */
|
|
91
|
+
readonly MAX_PARTICLES: 500;
|
|
92
|
+
/** Frame time budget in ms (targeting 60fps) */
|
|
93
|
+
readonly FRAME_BUDGET: 16.67;
|
|
94
|
+
/** Minimum opacity before particle is considered dead */
|
|
95
|
+
readonly MIN_OPACITY: 0.01;
|
|
96
|
+
/** Minimum size before particle is considered dead */
|
|
97
|
+
readonly MIN_SIZE: 0.5;
|
|
98
|
+
/** Device pixel ratio limit for high-DPI displays */
|
|
99
|
+
readonly MAX_DPR: 2;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Canvas cleanup delay in milliseconds
|
|
103
|
+
*/
|
|
104
|
+
export declare const CLEANUP_DELAY = 100;
|
|
105
|
+
/**
|
|
106
|
+
* Star shape points configuration
|
|
107
|
+
*/
|
|
108
|
+
export declare const STAR_POINTS = 5;
|
|
109
|
+
export declare const STAR_INNER_RATIO = 0.5;
|
|
110
|
+
/**
|
|
111
|
+
* Color palettes for presets
|
|
112
|
+
*/
|
|
113
|
+
export declare const COLOR_PALETTES: {
|
|
114
|
+
readonly rainbow: readonly string[];
|
|
115
|
+
readonly pride: readonly ["#E40303", "#FF8C00", "#FFED00", "#008026", "#24408E", "#732982"];
|
|
116
|
+
readonly christmas: readonly ["#C41E3A", "#165B33", "#FFD700", "#FFFFFF", "#BB2528"];
|
|
117
|
+
readonly halloween: readonly ["#FF6600", "#000000", "#8B008B", "#00FF00", "#FFD700"];
|
|
118
|
+
readonly pastel: readonly ["#FFB3BA", "#FFDFBA", "#FFFFBA", "#BAFFC9", "#BAE1FF"];
|
|
119
|
+
readonly neon: readonly ["#FF00FF", "#00FFFF", "#FF0080", "#80FF00", "#FF8000"];
|
|
120
|
+
readonly gold: readonly ["#FFD700", "#DAA520", "#B8860B", "#FFC125", "#FFDF00"];
|
|
121
|
+
readonly silver: readonly ["#C0C0C0", "#A8A8A8", "#D3D3D3", "#DCDCDC", "#E8E8E8"];
|
|
122
|
+
readonly hearts: readonly ["#FF69B4", "#FF1493", "#FF007F", "#DC143C", "#FFB6C1"];
|
|
123
|
+
readonly ocean: readonly ["#006994", "#00CED1", "#20B2AA", "#48D1CC", "#87CEEB"];
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Emoji sets for presets
|
|
127
|
+
*/
|
|
128
|
+
export declare const EMOJI_SETS: {
|
|
129
|
+
readonly celebration: readonly ["🎉", "🎊", "🥳", "✨", "🎈"];
|
|
130
|
+
readonly hearts: readonly ["❤️", "💕", "💖", "💗", "💓", "💘"];
|
|
131
|
+
readonly stars: readonly ["⭐", "🌟", "✨", "💫", "⚡"];
|
|
132
|
+
readonly money: readonly ["💰", "💵", "💸", "🤑", "💎"];
|
|
133
|
+
readonly christmas: readonly ["🎄", "🎅", "🎁", "❄️", "⭐"];
|
|
134
|
+
readonly halloween: readonly ["🎃", "👻", "🦇", "🕷️", "💀"];
|
|
135
|
+
readonly birthday: readonly ["🎂", "🎁", "🎈", "🎉", "🥳"];
|
|
136
|
+
readonly food: readonly ["🍕", "🍔", "🍟", "🌭", "🍿"];
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Preset configurations for quick setup
|
|
140
|
+
*/
|
|
141
|
+
export declare const PRESETS: Record<PresetName, PresetConfig>;
|
|
142
|
+
/**
|
|
143
|
+
* Get preset options by name
|
|
144
|
+
*/
|
|
145
|
+
export declare function getPreset(name: PresetName): ConfettiBurstOptions;
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,YAAY,EACZ,UAAU,EACV,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAWlC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,aAapB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAItB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAA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AAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;CAWjB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;CASb,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,CAyT3C,CAAC;AAEX;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,oBAAoB,CAEhE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hooks for confetti animations
|
|
3
|
+
*
|
|
4
|
+
* Provides convenient React hooks for triggering confetti bursts
|
|
5
|
+
* with proper lifecycle management and cleanup.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConfettiBurstOptions, BurstOrigin, ExplosionHandle, UseConfettiReturn } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Main hook for triggering confetti animations
|
|
10
|
+
*
|
|
11
|
+
* @returns Object with fire functions and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const { fire, isActive } = useConfetti();
|
|
16
|
+
*
|
|
17
|
+
* const handleClick = (e) => {
|
|
18
|
+
* fire({ x: e.clientX, y: e.clientY });
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function useConfetti(): UseConfettiReturn;
|
|
23
|
+
/**
|
|
24
|
+
* Hook for confetti triggered by a ref element
|
|
25
|
+
*
|
|
26
|
+
* @param options - Confetti configuration options
|
|
27
|
+
* @returns Ref to attach to trigger element and fire function
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const { ref, fire } = useConfettiTrigger();
|
|
32
|
+
*
|
|
33
|
+
* return (
|
|
34
|
+
* <button ref={ref} onClick={fire}>
|
|
35
|
+
* Celebrate!
|
|
36
|
+
* </button>
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function useConfettiTrigger<T extends HTMLElement = HTMLElement>(options?: ConfettiBurstOptions): {
|
|
41
|
+
ref: React.RefObject<T>;
|
|
42
|
+
fire: () => ExplosionHandle | null;
|
|
43
|
+
isActive: boolean;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Hook for auto-firing confetti when a condition becomes true
|
|
47
|
+
*
|
|
48
|
+
* @param condition - When true, fires confetti
|
|
49
|
+
* @param origin - Origin point for the burst
|
|
50
|
+
* @param options - Confetti configuration options
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* const [isComplete, setIsComplete] = useState(false);
|
|
55
|
+
*
|
|
56
|
+
* useConfettiOnCondition(isComplete, { x: 500, y: 300 });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function useConfettiOnCondition(condition: boolean, origin: BurstOrigin, options?: ConfettiBurstOptions): void;
|
|
60
|
+
/**
|
|
61
|
+
* Hook for sequencing multiple confetti bursts
|
|
62
|
+
*
|
|
63
|
+
* @param bursts - Array of burst configurations with delays
|
|
64
|
+
* @returns Start function and active state
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* const { start, isActive } = useConfettiSequence([
|
|
69
|
+
* { origin: { x: 100, y: 100 }, delay: 0 },
|
|
70
|
+
* { origin: { x: 300, y: 100 }, delay: 200 },
|
|
71
|
+
* { origin: { x: 500, y: 100 }, delay: 400 },
|
|
72
|
+
* ]);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function useConfettiSequence(bursts: Array<{
|
|
76
|
+
origin: BurstOrigin;
|
|
77
|
+
options?: ConfettiBurstOptions;
|
|
78
|
+
delay: number;
|
|
79
|
+
}>): {
|
|
80
|
+
start: () => void;
|
|
81
|
+
isActive: boolean;
|
|
82
|
+
cancel: () => void;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Hook for viewport-centered confetti
|
|
86
|
+
*
|
|
87
|
+
* @param options - Confetti configuration options
|
|
88
|
+
* @returns Fire function for center-screen confetti
|
|
89
|
+
*/
|
|
90
|
+
export declare function useConfettiCenter(options?: ConfettiBurstOptions): {
|
|
91
|
+
fire: () => ExplosionHandle;
|
|
92
|
+
isActive: boolean;
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAOjB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,IAAI,iBAAiB,CAmG/C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACpE,OAAO,CAAC,EAAE,oBAAoB,GAC7B;IACD,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,EAAE,MAAM,eAAe,GAAG,IAAI,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;CACnB,CASA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,IAAI,CAiBN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,GACD;IACD,KAAK,EAA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