celebrate-js 0.1.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 +170 -0
- package/dist/index.cjs +625 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +599 -0
- package/package.json +56 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
celebrate: () => celebrate
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(index_exports);
|
|
25
|
+
|
|
26
|
+
// src/effects/confetti.ts
|
|
27
|
+
function confetti(options = {}) {
|
|
28
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const duration = options.duration ?? 2e3;
|
|
32
|
+
const particleCount = options.particleCount ?? 150;
|
|
33
|
+
const colors = options.colors && options.colors.length > 0 ? options.colors : ["#FFC700", "#FF0000", "#2E3191", "#46c741ff"];
|
|
34
|
+
const canvas = document.createElement("canvas");
|
|
35
|
+
const ctx = canvas.getContext("2d");
|
|
36
|
+
canvas.style.position = "fixed";
|
|
37
|
+
canvas.style.top = "0";
|
|
38
|
+
canvas.style.left = "0";
|
|
39
|
+
canvas.style.pointerEvents = "none";
|
|
40
|
+
canvas.style.zIndex = "9999";
|
|
41
|
+
document.body.appendChild(canvas);
|
|
42
|
+
const resize = () => {
|
|
43
|
+
canvas.width = window.innerWidth;
|
|
44
|
+
canvas.height = window.innerHeight;
|
|
45
|
+
};
|
|
46
|
+
resize();
|
|
47
|
+
window.addEventListener("resize", resize);
|
|
48
|
+
const particles = Array.from({ length: particleCount }).map(() => ({
|
|
49
|
+
x: Math.random() * canvas.width,
|
|
50
|
+
y: Math.random() * canvas.height - canvas.height,
|
|
51
|
+
size: Math.random() * 6 + 4,
|
|
52
|
+
color: colors[Math.floor(Math.random() * colors.length)],
|
|
53
|
+
velocityX: Math.random() * 4 - 2,
|
|
54
|
+
velocityY: Math.random() * 6 + 4,
|
|
55
|
+
rotation: Math.random() * 360
|
|
56
|
+
}));
|
|
57
|
+
const start = performance.now();
|
|
58
|
+
function draw(now) {
|
|
59
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
60
|
+
for (const p of particles) {
|
|
61
|
+
p.x += p.velocityX;
|
|
62
|
+
p.y += p.velocityY;
|
|
63
|
+
p.rotation += 5;
|
|
64
|
+
ctx.save();
|
|
65
|
+
ctx.translate(p.x, p.y);
|
|
66
|
+
ctx.rotate(p.rotation * Math.PI / 180);
|
|
67
|
+
ctx.fillStyle = p.color;
|
|
68
|
+
ctx.fillRect(-p.size / 2, -p.size / 2, p.size, p.size);
|
|
69
|
+
ctx.restore();
|
|
70
|
+
}
|
|
71
|
+
if (now - start < duration) {
|
|
72
|
+
requestAnimationFrame(draw);
|
|
73
|
+
} else {
|
|
74
|
+
cleanup();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function cleanup() {
|
|
78
|
+
window.removeEventListener("resize", resize);
|
|
79
|
+
canvas.remove();
|
|
80
|
+
}
|
|
81
|
+
requestAnimationFrame(draw);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/effects/balloons.ts
|
|
85
|
+
function balloons(options = {}) {
|
|
86
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const duration = options.duration ?? 3e3;
|
|
90
|
+
const count = options.particleCount ?? 20;
|
|
91
|
+
const colors = options.colors && options.colors.length > 0 ? options.colors : ["#ff6b6b", "#ffd93d", "#6bcb77", "#4d96ff", "#c77dff"];
|
|
92
|
+
const canvas = document.createElement("canvas");
|
|
93
|
+
const ctx = canvas.getContext("2d");
|
|
94
|
+
canvas.style.position = "fixed";
|
|
95
|
+
canvas.style.top = "0";
|
|
96
|
+
canvas.style.left = "0";
|
|
97
|
+
canvas.style.pointerEvents = "none";
|
|
98
|
+
canvas.style.zIndex = "9999";
|
|
99
|
+
document.body.appendChild(canvas);
|
|
100
|
+
const resize = () => {
|
|
101
|
+
canvas.width = window.innerWidth;
|
|
102
|
+
canvas.height = window.innerHeight;
|
|
103
|
+
};
|
|
104
|
+
resize();
|
|
105
|
+
window.addEventListener("resize", resize);
|
|
106
|
+
const balloons2 = Array.from({ length: count }).map(() => ({
|
|
107
|
+
x: Math.random() * canvas.width,
|
|
108
|
+
y: canvas.height + Math.random() * canvas.height,
|
|
109
|
+
radius: Math.random() * 20 + 20,
|
|
110
|
+
color: colors[Math.floor(Math.random() * colors.length)],
|
|
111
|
+
speed: Math.random() * 2 + 1.2,
|
|
112
|
+
sway: Math.random() * 2 + 1
|
|
113
|
+
}));
|
|
114
|
+
const start = performance.now();
|
|
115
|
+
function draw(now) {
|
|
116
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
117
|
+
balloons2.forEach((b, i) => {
|
|
118
|
+
b.y -= b.speed;
|
|
119
|
+
b.x += Math.sin(now / 300 + i) * b.sway;
|
|
120
|
+
const gradient = ctx.createRadialGradient(
|
|
121
|
+
b.x - b.radius * 0.3,
|
|
122
|
+
b.y - b.radius * 0.3,
|
|
123
|
+
b.radius * 0.2,
|
|
124
|
+
b.x,
|
|
125
|
+
b.y,
|
|
126
|
+
b.radius
|
|
127
|
+
);
|
|
128
|
+
gradient.addColorStop(0, "#ffffffaa");
|
|
129
|
+
gradient.addColorStop(0.3, b.color);
|
|
130
|
+
gradient.addColorStop(1, "#00000022");
|
|
131
|
+
ctx.beginPath();
|
|
132
|
+
ctx.ellipse(b.x, b.y, b.radius * 0.8, b.radius, 0, 0, Math.PI * 2);
|
|
133
|
+
ctx.fillStyle = gradient;
|
|
134
|
+
ctx.fill();
|
|
135
|
+
const stringLength = 35;
|
|
136
|
+
const swayOffset = Math.sin(now / 150 + i) * b.sway * 4;
|
|
137
|
+
ctx.beginPath();
|
|
138
|
+
ctx.moveTo(b.x, b.y + b.radius);
|
|
139
|
+
ctx.quadraticCurveTo(
|
|
140
|
+
b.x + swayOffset,
|
|
141
|
+
b.y + b.radius + stringLength / 2,
|
|
142
|
+
b.x,
|
|
143
|
+
b.y + b.radius + stringLength
|
|
144
|
+
);
|
|
145
|
+
ctx.strokeStyle = "#555";
|
|
146
|
+
ctx.lineWidth = 1;
|
|
147
|
+
ctx.stroke();
|
|
148
|
+
});
|
|
149
|
+
if (now - start < duration) {
|
|
150
|
+
requestAnimationFrame(draw);
|
|
151
|
+
} else {
|
|
152
|
+
cleanup();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function cleanup() {
|
|
156
|
+
window.removeEventListener("resize", resize);
|
|
157
|
+
canvas.remove();
|
|
158
|
+
}
|
|
159
|
+
requestAnimationFrame(draw);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/effects/popper.ts
|
|
163
|
+
function popper(options = {}) {
|
|
164
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const duration = options.duration ?? 1800;
|
|
168
|
+
const particleCount = options.particleCount ?? 120;
|
|
169
|
+
const colors = options.colors && options.colors.length > 0 ? options.colors : ["#FFC700", "#FF0000", "#2E3191", "#41BBC7", "#7CFFCB"];
|
|
170
|
+
const canvas = document.createElement("canvas");
|
|
171
|
+
const ctx = canvas.getContext("2d");
|
|
172
|
+
canvas.style.position = "fixed";
|
|
173
|
+
canvas.style.top = "0";
|
|
174
|
+
canvas.style.left = "0";
|
|
175
|
+
canvas.style.pointerEvents = "none";
|
|
176
|
+
canvas.style.zIndex = "9999";
|
|
177
|
+
document.body.appendChild(canvas);
|
|
178
|
+
const resize = () => {
|
|
179
|
+
canvas.width = window.innerWidth;
|
|
180
|
+
canvas.height = window.innerHeight;
|
|
181
|
+
};
|
|
182
|
+
resize();
|
|
183
|
+
window.addEventListener("resize", resize);
|
|
184
|
+
const particles = [];
|
|
185
|
+
const createSide = (side) => {
|
|
186
|
+
for (let i = 0; i < particleCount / 2; i++) {
|
|
187
|
+
particles.push({
|
|
188
|
+
x: side === "left" ? 0 : canvas.width,
|
|
189
|
+
y: canvas.height * 0.6,
|
|
190
|
+
size: Math.random() * 6 + 4,
|
|
191
|
+
color: colors[Math.floor(Math.random() * colors.length)],
|
|
192
|
+
vx: side === "left" ? Math.random() * 4 + 2 : -(Math.random() * 4 + 2),
|
|
193
|
+
vy: Math.random() * -14 - 10,
|
|
194
|
+
rotation: Math.random() * 360,
|
|
195
|
+
rotationSpeed: Math.random() * 10 - 5
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
createSide("left");
|
|
200
|
+
createSide("right");
|
|
201
|
+
const gravity = 0.45;
|
|
202
|
+
const start = performance.now();
|
|
203
|
+
function draw(now) {
|
|
204
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
205
|
+
particles.forEach((p) => {
|
|
206
|
+
p.vy += gravity;
|
|
207
|
+
p.vx *= 0.99;
|
|
208
|
+
p.vy *= 0.99;
|
|
209
|
+
p.x += p.vx;
|
|
210
|
+
p.y += p.vy;
|
|
211
|
+
p.rotation += p.rotationSpeed;
|
|
212
|
+
ctx.save();
|
|
213
|
+
ctx.translate(p.x, p.y);
|
|
214
|
+
ctx.rotate(p.rotation * Math.PI / 180);
|
|
215
|
+
ctx.fillStyle = p.color;
|
|
216
|
+
ctx.fillRect(-p.size / 2, -p.size / 2, p.size, p.size);
|
|
217
|
+
ctx.fillStyle = "#ffffff55";
|
|
218
|
+
ctx.fillRect(
|
|
219
|
+
-p.size / 2,
|
|
220
|
+
-p.size / 2,
|
|
221
|
+
p.size * 0.4,
|
|
222
|
+
p.size * 0.4
|
|
223
|
+
);
|
|
224
|
+
ctx.restore();
|
|
225
|
+
});
|
|
226
|
+
if (now - start < duration) {
|
|
227
|
+
requestAnimationFrame(draw);
|
|
228
|
+
} else {
|
|
229
|
+
cleanup();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function cleanup() {
|
|
233
|
+
window.removeEventListener("resize", resize);
|
|
234
|
+
canvas.remove();
|
|
235
|
+
}
|
|
236
|
+
requestAnimationFrame(draw);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/effects/fireworks.ts
|
|
240
|
+
function fireworks(options = {}) {
|
|
241
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const duration = options.duration ?? 4e3;
|
|
245
|
+
const burstCount = options.count ?? 5;
|
|
246
|
+
const interval = options.interval ?? 500;
|
|
247
|
+
const colors = options.colors && options.colors.length > 0 ? options.colors : ["#ff5252", "#ffd740", "#40c4ff", "#69f0ae", "#e040fb"];
|
|
248
|
+
const canvas = document.createElement("canvas");
|
|
249
|
+
const ctx = canvas.getContext("2d");
|
|
250
|
+
canvas.style.position = "fixed";
|
|
251
|
+
canvas.style.top = "0";
|
|
252
|
+
canvas.style.left = "0";
|
|
253
|
+
canvas.style.pointerEvents = "none";
|
|
254
|
+
canvas.style.zIndex = "9999";
|
|
255
|
+
document.body.appendChild(canvas);
|
|
256
|
+
const resize = () => {
|
|
257
|
+
canvas.width = window.innerWidth;
|
|
258
|
+
canvas.height = window.innerHeight;
|
|
259
|
+
};
|
|
260
|
+
resize();
|
|
261
|
+
window.addEventListener("resize", resize);
|
|
262
|
+
let particles = [];
|
|
263
|
+
let bursts = 0;
|
|
264
|
+
function createBurst() {
|
|
265
|
+
const x = Math.random() * canvas.width;
|
|
266
|
+
const y = Math.random() * canvas.height * 0.5;
|
|
267
|
+
const color = colors[Math.floor(Math.random() * colors.length)];
|
|
268
|
+
const count = 60;
|
|
269
|
+
for (let i = 0; i < count; i++) {
|
|
270
|
+
const angle = Math.PI * 2 * i / count;
|
|
271
|
+
const speed = Math.random() * 4 + 2;
|
|
272
|
+
particles.push({
|
|
273
|
+
x,
|
|
274
|
+
y,
|
|
275
|
+
vx: Math.cos(angle) * speed,
|
|
276
|
+
vy: Math.sin(angle) * speed,
|
|
277
|
+
alpha: 1,
|
|
278
|
+
color
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const start = performance.now();
|
|
283
|
+
let lastBurst = 0;
|
|
284
|
+
function draw(now) {
|
|
285
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
286
|
+
if (bursts < burstCount && now - lastBurst > interval) {
|
|
287
|
+
createBurst();
|
|
288
|
+
bursts++;
|
|
289
|
+
lastBurst = now;
|
|
290
|
+
}
|
|
291
|
+
particles.forEach((p) => {
|
|
292
|
+
p.x += p.vx;
|
|
293
|
+
p.y += p.vy;
|
|
294
|
+
p.vy += 0.04;
|
|
295
|
+
p.alpha -= 0.015;
|
|
296
|
+
ctx.beginPath();
|
|
297
|
+
ctx.arc(p.x, p.y, 2, 0, Math.PI * 2);
|
|
298
|
+
ctx.fillStyle = p.color.replace(")", `, ${p.alpha})`).startsWith("rgb") ? p.color : p.color;
|
|
299
|
+
ctx.globalAlpha = Math.max(p.alpha, 0);
|
|
300
|
+
ctx.fill();
|
|
301
|
+
});
|
|
302
|
+
ctx.globalAlpha = 1;
|
|
303
|
+
particles = particles.filter((p) => p.alpha > 0);
|
|
304
|
+
if (now - start < duration || particles.length > 0) {
|
|
305
|
+
requestAnimationFrame(draw);
|
|
306
|
+
} else {
|
|
307
|
+
cleanup();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function cleanup() {
|
|
311
|
+
window.removeEventListener("resize", resize);
|
|
312
|
+
canvas.remove();
|
|
313
|
+
}
|
|
314
|
+
requestAnimationFrame(draw);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/effects/bubbles.ts
|
|
318
|
+
function bubbles(options) {
|
|
319
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const duration = options.duration ?? 3e3;
|
|
323
|
+
const count = options.particleCount ?? 25;
|
|
324
|
+
const canvas = document.createElement("canvas");
|
|
325
|
+
const ctx = canvas.getContext("2d");
|
|
326
|
+
canvas.style.position = "fixed";
|
|
327
|
+
canvas.style.top = "0";
|
|
328
|
+
canvas.style.left = "0";
|
|
329
|
+
canvas.style.pointerEvents = "none";
|
|
330
|
+
canvas.style.zIndex = "9999";
|
|
331
|
+
document.body.appendChild(canvas);
|
|
332
|
+
const resize = () => {
|
|
333
|
+
canvas.width = window.innerWidth;
|
|
334
|
+
canvas.height = window.innerHeight;
|
|
335
|
+
};
|
|
336
|
+
resize();
|
|
337
|
+
window.addEventListener("resize", resize);
|
|
338
|
+
const bubbles2 = Array.from({ length: count }).map(() => ({
|
|
339
|
+
x: Math.random() * canvas.width,
|
|
340
|
+
y: canvas.height + Math.random() * 100,
|
|
341
|
+
radius: Math.random() * 15 + 10,
|
|
342
|
+
speed: Math.random() * 2.1 + 1.4,
|
|
343
|
+
drift: Math.random() * 1.5 - 0.75,
|
|
344
|
+
alpha: Math.random() * 0.4 + 0.4
|
|
345
|
+
}));
|
|
346
|
+
const start = performance.now();
|
|
347
|
+
function draw(now) {
|
|
348
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
349
|
+
bubbles2.forEach((b) => {
|
|
350
|
+
b.y -= b.speed;
|
|
351
|
+
b.x += Math.sin(now / 500) * b.drift;
|
|
352
|
+
if (b.y < canvas.height * 0.3) {
|
|
353
|
+
b.alpha = Math.max(0, b.alpha - 0.01);
|
|
354
|
+
}
|
|
355
|
+
ctx.beginPath();
|
|
356
|
+
ctx.arc(b.x, b.y, b.radius, 0, Math.PI * 2);
|
|
357
|
+
ctx.fillStyle = `rgba(180, 220, 255, ${b.alpha * 0.4})`;
|
|
358
|
+
ctx.fill();
|
|
359
|
+
ctx.strokeStyle = `rgba(255,255,255,${b.alpha})`;
|
|
360
|
+
ctx.lineWidth = 2;
|
|
361
|
+
ctx.stroke();
|
|
362
|
+
ctx.beginPath();
|
|
363
|
+
ctx.arc(
|
|
364
|
+
b.x - b.radius / 3,
|
|
365
|
+
b.y - b.radius / 3,
|
|
366
|
+
b.radius / 4,
|
|
367
|
+
0,
|
|
368
|
+
Math.PI * 2
|
|
369
|
+
);
|
|
370
|
+
ctx.strokeStyle = `rgba(255,255,255,${b.alpha * 0.6})`;
|
|
371
|
+
ctx.stroke();
|
|
372
|
+
});
|
|
373
|
+
if (now - start < duration) {
|
|
374
|
+
requestAnimationFrame(draw);
|
|
375
|
+
} else {
|
|
376
|
+
cleanup();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function cleanup() {
|
|
380
|
+
window.removeEventListener("resize", resize);
|
|
381
|
+
canvas.remove();
|
|
382
|
+
}
|
|
383
|
+
requestAnimationFrame(draw);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/effects/emojis.ts
|
|
387
|
+
function emojis(options) {
|
|
388
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const duration = options.duration ?? 3e3;
|
|
392
|
+
const count = options.particleCount ?? 30;
|
|
393
|
+
const emojiSet = options.emojis ?? ["\u{1F389}", "\u2728", "\u{1F525}", "\u{1F4AF}", "\u{1F60D}"];
|
|
394
|
+
const canvas = document.createElement("canvas");
|
|
395
|
+
const ctx = canvas.getContext("2d");
|
|
396
|
+
canvas.style.position = "fixed";
|
|
397
|
+
canvas.style.top = "0";
|
|
398
|
+
canvas.style.left = "0";
|
|
399
|
+
canvas.style.pointerEvents = "none";
|
|
400
|
+
canvas.style.zIndex = "9999";
|
|
401
|
+
document.body.appendChild(canvas);
|
|
402
|
+
const resize = () => {
|
|
403
|
+
canvas.width = window.innerWidth;
|
|
404
|
+
canvas.height = window.innerHeight;
|
|
405
|
+
};
|
|
406
|
+
resize();
|
|
407
|
+
window.addEventListener("resize", resize);
|
|
408
|
+
const emojis2 = Array.from({ length: count }).map(() => ({
|
|
409
|
+
x: Math.random() * canvas.width,
|
|
410
|
+
y: Math.random() * -canvas.height,
|
|
411
|
+
char: emojiSet[Math.floor(Math.random() * emojiSet.length)],
|
|
412
|
+
size: Math.random() * 20 + 20,
|
|
413
|
+
speed: Math.random() * 2.5 + 1.5,
|
|
414
|
+
drift: Math.random() * 1.5 - 0.75,
|
|
415
|
+
rotation: Math.random() * 360,
|
|
416
|
+
rotationSpeed: Math.random() * 4 - 2,
|
|
417
|
+
alpha: 1
|
|
418
|
+
}));
|
|
419
|
+
const start = performance.now();
|
|
420
|
+
function draw(now) {
|
|
421
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
422
|
+
emojis2.forEach((e) => {
|
|
423
|
+
e.y += e.speed;
|
|
424
|
+
e.x += Math.sin(now / 400) * e.drift;
|
|
425
|
+
e.rotation += e.rotationSpeed;
|
|
426
|
+
if (e.y > canvas.height * 0.8) {
|
|
427
|
+
e.alpha = Math.max(0, e.alpha - 0.02);
|
|
428
|
+
}
|
|
429
|
+
ctx.save();
|
|
430
|
+
ctx.translate(e.x, e.y);
|
|
431
|
+
ctx.rotate(e.rotation * Math.PI / 180);
|
|
432
|
+
ctx.globalAlpha = e.alpha;
|
|
433
|
+
ctx.font = `${e.size}px serif`;
|
|
434
|
+
ctx.textAlign = "center";
|
|
435
|
+
ctx.textBaseline = "middle";
|
|
436
|
+
ctx.fillText(e.char, 0, 0);
|
|
437
|
+
ctx.restore();
|
|
438
|
+
});
|
|
439
|
+
if (now - start < duration) {
|
|
440
|
+
requestAnimationFrame(draw);
|
|
441
|
+
} else {
|
|
442
|
+
cleanup();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function cleanup() {
|
|
446
|
+
window.removeEventListener("resize", resize);
|
|
447
|
+
canvas.remove();
|
|
448
|
+
}
|
|
449
|
+
requestAnimationFrame(draw);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/effects/stars.ts
|
|
453
|
+
function stars(options) {
|
|
454
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const duration = options.duration ?? 3e3;
|
|
458
|
+
const count = options.count ?? 5;
|
|
459
|
+
const interval = options.interval ?? 500;
|
|
460
|
+
const canvas = document.createElement("canvas");
|
|
461
|
+
const ctx = canvas.getContext("2d");
|
|
462
|
+
canvas.style.position = "fixed";
|
|
463
|
+
canvas.style.top = "0";
|
|
464
|
+
canvas.style.left = "0";
|
|
465
|
+
canvas.style.pointerEvents = "none";
|
|
466
|
+
canvas.style.zIndex = "9999";
|
|
467
|
+
document.body.appendChild(canvas);
|
|
468
|
+
const resize = () => {
|
|
469
|
+
canvas.width = window.innerWidth;
|
|
470
|
+
canvas.height = window.innerHeight;
|
|
471
|
+
};
|
|
472
|
+
resize();
|
|
473
|
+
window.addEventListener("resize", resize);
|
|
474
|
+
const stars2 = [];
|
|
475
|
+
const start = performance.now();
|
|
476
|
+
let spawned = 0;
|
|
477
|
+
let lastSpawn = 0;
|
|
478
|
+
function spawnStar() {
|
|
479
|
+
const fromLeft = Math.random() > 0.5;
|
|
480
|
+
stars2.push({
|
|
481
|
+
x: fromLeft ? -100 : canvas.width + 100,
|
|
482
|
+
y: Math.random() * canvas.height * 0.4,
|
|
483
|
+
vx: fromLeft ? Math.random() * 12 + 8 : -(Math.random() * 12 + 8),
|
|
484
|
+
vy: Math.random() * 6 + 4,
|
|
485
|
+
length: Math.random() * 80 + 60,
|
|
486
|
+
alpha: 1
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
function draw(now) {
|
|
490
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
491
|
+
if (spawned < count && now - lastSpawn > interval) {
|
|
492
|
+
spawnStar();
|
|
493
|
+
spawned++;
|
|
494
|
+
lastSpawn = now;
|
|
495
|
+
}
|
|
496
|
+
stars2.forEach((s, i) => {
|
|
497
|
+
s.x += s.vx;
|
|
498
|
+
s.y += s.vy;
|
|
499
|
+
s.alpha -= 0.015;
|
|
500
|
+
ctx.beginPath();
|
|
501
|
+
ctx.moveTo(s.x, s.y);
|
|
502
|
+
ctx.lineTo(
|
|
503
|
+
s.x - s.vx * 4,
|
|
504
|
+
s.y - s.vy * 4
|
|
505
|
+
);
|
|
506
|
+
ctx.strokeStyle = `rgba(255,255,120,${s.alpha})`;
|
|
507
|
+
ctx.lineWidth = 2;
|
|
508
|
+
ctx.lineCap = "round";
|
|
509
|
+
ctx.stroke();
|
|
510
|
+
if (s.alpha <= 0) {
|
|
511
|
+
stars2.splice(i, 1);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
if (now - start < duration || stars2.length > 0) {
|
|
515
|
+
requestAnimationFrame(draw);
|
|
516
|
+
} else {
|
|
517
|
+
cleanup();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function cleanup() {
|
|
521
|
+
window.removeEventListener("resize", resize);
|
|
522
|
+
canvas.remove();
|
|
523
|
+
}
|
|
524
|
+
requestAnimationFrame(draw);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/effects/snowfall.ts
|
|
528
|
+
function snowfall(options) {
|
|
529
|
+
if (options.respectReducedMotion && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const duration = options.duration ?? 5e3;
|
|
533
|
+
const count = options.particleCount ?? 60;
|
|
534
|
+
const canvas = document.createElement("canvas");
|
|
535
|
+
const ctx = canvas.getContext("2d");
|
|
536
|
+
canvas.style.position = "fixed";
|
|
537
|
+
canvas.style.top = "0";
|
|
538
|
+
canvas.style.left = "0";
|
|
539
|
+
canvas.style.pointerEvents = "none";
|
|
540
|
+
canvas.style.zIndex = "9999";
|
|
541
|
+
document.body.appendChild(canvas);
|
|
542
|
+
const resize = () => {
|
|
543
|
+
canvas.width = window.innerWidth;
|
|
544
|
+
canvas.height = window.innerHeight;
|
|
545
|
+
};
|
|
546
|
+
resize();
|
|
547
|
+
window.addEventListener("resize", resize);
|
|
548
|
+
const flakes = Array.from({ length: count }).map(() => ({
|
|
549
|
+
x: Math.random() * canvas.width,
|
|
550
|
+
y: Math.random() * -canvas.height,
|
|
551
|
+
radius: Math.random() * 2.5 + 1,
|
|
552
|
+
speed: Math.random() * 0.6 + 0.3,
|
|
553
|
+
drift: Math.random() * 0.6 - 0.3,
|
|
554
|
+
alpha: Math.random() * 0.5 + 0.4
|
|
555
|
+
}));
|
|
556
|
+
const start = performance.now();
|
|
557
|
+
function draw(now) {
|
|
558
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
559
|
+
flakes.forEach((f) => {
|
|
560
|
+
f.y += f.speed;
|
|
561
|
+
f.x += Math.sin(now / 800) * f.drift;
|
|
562
|
+
if (f.y > canvas.height) {
|
|
563
|
+
f.y = -10;
|
|
564
|
+
f.x = Math.random() * canvas.width;
|
|
565
|
+
}
|
|
566
|
+
ctx.beginPath();
|
|
567
|
+
ctx.arc(f.x, f.y, f.radius, 0, Math.PI * 2);
|
|
568
|
+
ctx.fillStyle = `rgba(255,255,255,${f.alpha})`;
|
|
569
|
+
ctx.fill();
|
|
570
|
+
});
|
|
571
|
+
if (now - start < duration) {
|
|
572
|
+
requestAnimationFrame(draw);
|
|
573
|
+
} else {
|
|
574
|
+
cleanup();
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function cleanup() {
|
|
578
|
+
window.removeEventListener("resize", resize);
|
|
579
|
+
canvas.remove();
|
|
580
|
+
}
|
|
581
|
+
requestAnimationFrame(draw);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/index.ts
|
|
585
|
+
function celebrate(options = {}) {
|
|
586
|
+
const effect = options.effect ?? "confetti";
|
|
587
|
+
switch (effect) {
|
|
588
|
+
case "confetti":
|
|
589
|
+
confetti(options);
|
|
590
|
+
break;
|
|
591
|
+
case "balloons":
|
|
592
|
+
balloons(options);
|
|
593
|
+
break;
|
|
594
|
+
case "popper":
|
|
595
|
+
popper(options);
|
|
596
|
+
break;
|
|
597
|
+
case "fireworks":
|
|
598
|
+
fireworks(options);
|
|
599
|
+
break;
|
|
600
|
+
case "bubbles":
|
|
601
|
+
bubbles(options);
|
|
602
|
+
break;
|
|
603
|
+
case "emojis":
|
|
604
|
+
emojis(options);
|
|
605
|
+
break;
|
|
606
|
+
case "stars":
|
|
607
|
+
stars(options);
|
|
608
|
+
break;
|
|
609
|
+
case "snowfall":
|
|
610
|
+
snowfall(options);
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
celebrate.confetti = (o) => celebrate({ ...o, effect: "confetti" });
|
|
615
|
+
celebrate.balloons = (o) => celebrate({ ...o, effect: "balloons" });
|
|
616
|
+
celebrate.popper = (o) => celebrate({ ...o, effect: "popper" });
|
|
617
|
+
celebrate.fireworks = (o) => celebrate({ ...o, effect: "fireworks" });
|
|
618
|
+
celebrate.bubbles = (o) => celebrate({ ...o, effect: "bubbles" });
|
|
619
|
+
celebrate.emojis = (o) => celebrate({ ...o, effect: "emojis" });
|
|
620
|
+
celebrate.stars = (o) => celebrate({ ...o, effect: "stars" });
|
|
621
|
+
celebrate.snowfall = (o) => celebrate({ ...o, effect: "snowfall" });
|
|
622
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
623
|
+
0 && (module.exports = {
|
|
624
|
+
celebrate
|
|
625
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type CelebrateEffect = "confetti" | "balloons" | "popper" | "fireworks" | "bubbles" | "emojis" | "stars" | "snowfall";
|
|
2
|
+
interface CelebrateOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Which celebration effect to trigger
|
|
5
|
+
* @default "confetti"
|
|
6
|
+
*/
|
|
7
|
+
effect?: CelebrateEffect;
|
|
8
|
+
duration?: number;
|
|
9
|
+
particleCount?: number;
|
|
10
|
+
colors?: string[];
|
|
11
|
+
respectReducedMotion?: boolean;
|
|
12
|
+
count?: number;
|
|
13
|
+
interval?: number;
|
|
14
|
+
emojis?: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function celebrate(options?: CelebrateOptions): void;
|
|
18
|
+
declare namespace celebrate {
|
|
19
|
+
var confetti: (o?: CelebrateOptions) => void;
|
|
20
|
+
var balloons: (o?: CelebrateOptions) => void;
|
|
21
|
+
var popper: (o?: CelebrateOptions) => void;
|
|
22
|
+
var fireworks: (o?: CelebrateOptions) => void;
|
|
23
|
+
var bubbles: (o?: CelebrateOptions) => void;
|
|
24
|
+
var emojis: (o?: CelebrateOptions) => void;
|
|
25
|
+
var stars: (o?: CelebrateOptions) => void;
|
|
26
|
+
var snowfall: (o?: CelebrateOptions) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { celebrate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type CelebrateEffect = "confetti" | "balloons" | "popper" | "fireworks" | "bubbles" | "emojis" | "stars" | "snowfall";
|
|
2
|
+
interface CelebrateOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Which celebration effect to trigger
|
|
5
|
+
* @default "confetti"
|
|
6
|
+
*/
|
|
7
|
+
effect?: CelebrateEffect;
|
|
8
|
+
duration?: number;
|
|
9
|
+
particleCount?: number;
|
|
10
|
+
colors?: string[];
|
|
11
|
+
respectReducedMotion?: boolean;
|
|
12
|
+
count?: number;
|
|
13
|
+
interval?: number;
|
|
14
|
+
emojis?: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function celebrate(options?: CelebrateOptions): void;
|
|
18
|
+
declare namespace celebrate {
|
|
19
|
+
var confetti: (o?: CelebrateOptions) => void;
|
|
20
|
+
var balloons: (o?: CelebrateOptions) => void;
|
|
21
|
+
var popper: (o?: CelebrateOptions) => void;
|
|
22
|
+
var fireworks: (o?: CelebrateOptions) => void;
|
|
23
|
+
var bubbles: (o?: CelebrateOptions) => void;
|
|
24
|
+
var emojis: (o?: CelebrateOptions) => void;
|
|
25
|
+
var stars: (o?: CelebrateOptions) => void;
|
|
26
|
+
var snowfall: (o?: CelebrateOptions) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { celebrate };
|