@hyvor/design 2.1.10 → 2.1.11

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.
@@ -0,0 +1,7 @@
1
+ export declare function confetti(options?: {
2
+ particleCount?: number;
3
+ duration?: number;
4
+ zIndex?: number;
5
+ }): {
6
+ stop: () => void;
7
+ };
@@ -0,0 +1,102 @@
1
+ export function confetti(options = {}) {
2
+ const { particleCount = 220, duration = 12000, zIndex = 20000000 } = options;
3
+ const gravity = 0.18;
4
+ const drag = 0.96;
5
+ const canvas = document.createElement('canvas');
6
+ canvas.style.position = 'fixed';
7
+ canvas.style.top = '0';
8
+ canvas.style.left = '0';
9
+ canvas.style.width = '100vw';
10
+ canvas.style.height = '100vh';
11
+ canvas.style.pointerEvents = 'none';
12
+ canvas.style.zIndex = String(zIndex);
13
+ document.body.appendChild(canvas);
14
+ const ctx = canvas.getContext('2d');
15
+ canvas.width = window.innerWidth;
16
+ canvas.height = window.innerHeight;
17
+ const colors = ['#ffba6b', '#8cdaff', '#b5ffb0', '#ff9090', '#ffbfff', '#d894ff', '#fff79b'];
18
+ const particles = [];
19
+ let animationFrameId;
20
+ let timeoutId = null;
21
+ let running = true;
22
+ const originX = canvas.width / 2;
23
+ const originY = canvas.height / 2;
24
+ const createParticle = () => {
25
+ const angle = Math.random() * Math.PI * 2;
26
+ const speed = Math.random() * 16 + 10;
27
+ return {
28
+ x: originX + (Math.random() - 0.5) * 40,
29
+ y: originY + (Math.random() - 0.5) * 40,
30
+ size: Math.random() * 9 + 5,
31
+ color: colors[Math.floor(Math.random() * colors.length)],
32
+ velocityX: Math.cos(angle) * speed,
33
+ velocityY: Math.sin(angle) * speed,
34
+ rotation: Math.random() * 360,
35
+ rotationSpeed: Math.random() * 12 - 6,
36
+ wobble: Math.random() * Math.PI * 2,
37
+ wobbleSpeed: Math.random() * 0.1 + 0.05
38
+ };
39
+ };
40
+ const drawParticle = (particle) => {
41
+ ctx.save();
42
+ ctx.translate(particle.x, particle.y);
43
+ ctx.rotate((particle.rotation * Math.PI) / 180);
44
+ ctx.fillStyle = particle.color;
45
+ ctx.beginPath();
46
+ ctx.roundRect(-particle.size / 2, -particle.size / 2, particle.size, particle.size, 1);
47
+ ctx.fill();
48
+ ctx.restore();
49
+ };
50
+ const updateParticles = () => {
51
+ for (const particle of particles) {
52
+ particle.velocityX *= drag;
53
+ particle.velocityY = particle.velocityY * drag + gravity;
54
+ particle.wobble += particle.wobbleSpeed;
55
+ particle.x += particle.velocityX + Math.sin(particle.wobble) * 0.8;
56
+ particle.y += particle.velocityY;
57
+ particle.rotation += particle.rotationSpeed;
58
+ }
59
+ const remaining = particles.filter((particle) => particle.y - particle.size <= canvas.height);
60
+ particles.length = 0;
61
+ particles.push(...remaining);
62
+ };
63
+ const render = () => {
64
+ if (!running)
65
+ return;
66
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
67
+ for (const particle of particles)
68
+ drawParticle(particle);
69
+ updateParticles();
70
+ if (particles.length === 0) {
71
+ stopConfetti();
72
+ return;
73
+ }
74
+ animationFrameId = requestAnimationFrame(render);
75
+ };
76
+ let stopped = false;
77
+ const stopConfetti = () => {
78
+ if (stopped)
79
+ return;
80
+ stopped = true;
81
+ running = false;
82
+ cancelAnimationFrame(animationFrameId);
83
+ if (timeoutId !== null)
84
+ clearTimeout(timeoutId);
85
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
86
+ canvas.remove();
87
+ };
88
+ const startConfetti = () => {
89
+ particles.length = 0;
90
+ for (let i = 0; i < particleCount; i++)
91
+ particles.push(createParticle());
92
+ running = true;
93
+ render();
94
+ if (duration > 0) {
95
+ timeoutId = window.setTimeout(stopConfetti, duration);
96
+ }
97
+ };
98
+ startConfetti();
99
+ return {
100
+ stop: stopConfetti
101
+ };
102
+ }
@@ -98,6 +98,7 @@
98
98
  observer.observe(container, {
99
99
  attributes: true,
100
100
  attributeFilter: ['class'],
101
+ childList: true,
101
102
  subtree: true
102
103
  });
103
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyvor/design",
3
- "version": "2.1.10",
3
+ "version": "2.1.11",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "repository": {