@sarthak03dot/romantic-animations 1.0.3 → 1.2.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/src/index.js CHANGED
@@ -1,19 +1,224 @@
1
- import { initCanvas } from "./core/engine.js";
2
- import { floatingHearts } from "./animations/floatingHearts.js";
3
- import { heartTrail } from "./animations/heartTrail.js";
4
- import { heartBurst } from "./animations/heartBurst.js";
1
+ /**
2
+ * romantic-animations v2.0.0
3
+ * ───────────────────────────────────────────────────────
4
+ * A rich collection of canvas-based romantic & celebratory
5
+ * animations for the web.
6
+ *
7
+ * Usage (ESM):
8
+ * import { startFloatingHearts, stopAll } from '@sarthak03dot/romantic-animations';
9
+ * startFloatingHearts('my-container');
10
+ *
11
+ * Usage (UMD / CDN):
12
+ * <script src="...romantic-animations.umd.js"></script>
13
+ * <script>
14
+ * RomanticAnimations.startFloatingHearts('my-container');
15
+ * </script>
16
+ * ───────────────────────────────────────────────────────
17
+ */
5
18
 
6
- export function startFloatingHearts(containerId = 'body') {
7
- const canvas = initCanvas(containerId);
8
- floatingHearts(canvas);
19
+ import { initCanvas } from './core/engine.js';
20
+ import { floatingHearts } from './animations/floatingHearts.js';
21
+ import { heartTrail } from './animations/heartTrail.js';
22
+ import { heartBurst } from './animations/heartBurst.js';
23
+ import { sparkles } from './animations/sparkles.js';
24
+ import { loveRain } from './animations/loveRain.js';
25
+ import { confetti } from './animations/confetti.js';
26
+ import { fireworks } from './animations/fireworks.js';
27
+ import { starField } from './animations/starField.js';
28
+ import { butterflies } from './animations/butterfly.js';
29
+ import { magicDust } from './animations/magicDust.js';
30
+ import { floatingOrbs } from './animations/floatingOrbs.js';
31
+ import { shootingStars } from './animations/shootingStars.js';
32
+
33
+ // Track active sessions so stopAll() can clean up everything
34
+ const _sessions = new Map(); // containerId → { destroy, stop }
35
+ let _sessionId = 0;
36
+
37
+ /**
38
+ * Internal helper — boots a canvas and starts an animation fn.
39
+ * Returns a numeric session id that can be passed to stopAnimation().
40
+ *
41
+ * @param {string|HTMLElement} containerId
42
+ * @param {Function} animFn – the animation factory
43
+ * @param {object} options – user options forwarded to the animation
44
+ * @returns {number} session id
45
+ */
46
+ function _run(containerId, animFn, options = {}) {
47
+ const { canvas, destroy } = initCanvas(containerId, options);
48
+ const stop = animFn(canvas, options);
49
+ const id = ++_sessionId;
50
+ _sessions.set(id, { destroy, stop });
51
+ return id;
52
+ }
53
+
54
+ /**
55
+ * Stop a single animation by its session id.
56
+ * @param {number} id – returned by a start* call
57
+ */
58
+ export function stopAnimation(id) {
59
+ if (_sessions.has(id)) {
60
+ const s = _sessions.get(id);
61
+ if (typeof s.stop === 'function') s.stop();
62
+ s.destroy();
63
+ _sessions.delete(id);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Stop every running animation and clean up all canvases.
69
+ */
70
+ export function stopAll() {
71
+ _sessions.forEach((s) => {
72
+ if (typeof s.stop === 'function') s.stop();
73
+ s.destroy();
74
+ });
75
+ _sessions.clear();
76
+ }
77
+
78
+ // ─── Public API ───────────────────────────────────────────────────────────────
79
+
80
+ /**
81
+ * Floating hearts rising from the bottom.
82
+ * @param {string|HTMLElement} containerId
83
+ * @param {object} [options]
84
+ * @param {number} [options.count=0.12] – spawn probability per frame (0–1)
85
+ * @param {number} [options.minSize=14]
86
+ * @param {number} [options.maxSize=32]
87
+ * @param {number} [options.minSpeed=0.8]
88
+ * @param {number} [options.maxSpeed=2.4]
89
+ * @param {string[]} [options.colors]
90
+ * @param {boolean} [options.wobble=true] – sine-wave horizontal drift
91
+ * @param {boolean} [options.glow=true]
92
+ * @returns {number} session id
93
+ */
94
+ export function startFloatingHearts(containerId, options = {}) {
95
+ return _run(containerId, floatingHearts, options);
96
+ }
97
+
98
+ /**
99
+ * Heart trail that follows the cursor / touch.
100
+ * @param {string|HTMLElement} containerId
101
+ * @param {object} [options]
102
+ * @param {number} [options.minSize=6]
103
+ * @param {number} [options.maxSize=16]
104
+ * @param {number} [options.decay=0.025]
105
+ * @param {string[]} [options.colors]
106
+ * @param {boolean} [options.glow=true]
107
+ * @returns {number} session id
108
+ */
109
+ export function startHeartTrail(containerId, options = {}) {
110
+ return _run(containerId, heartTrail, options);
111
+ }
112
+
113
+ /**
114
+ * Heart burst on click / tap.
115
+ * @param {string|HTMLElement} containerId
116
+ * @param {object} [options]
117
+ * @param {number} [options.count=20] – particles per burst
118
+ * @param {string[]} [options.symbols] – 'heart' | 'star' | 'sparkle'
119
+ * @param {boolean} [options.glow=true]
120
+ * @returns {number} session id
121
+ */
122
+ export function startHeartBurst(containerId, options = {}) {
123
+ return _run(containerId, heartBurst, options);
124
+ }
125
+
126
+ /**
127
+ * Twinkling sparkle stars.
128
+ * @param {string|HTMLElement} containerId
129
+ * @param {object} [options]
130
+ * @param {number} [options.count=80]
131
+ * @param {number} [options.speed=0.5]
132
+ * @param {boolean} [options.glow=true]
133
+ * @returns {number} session id
134
+ */
135
+ export function startSparkles(containerId, options = {}) {
136
+ return _run(containerId, sparkles, options);
137
+ }
138
+
139
+ /**
140
+ * Rain of love emojis / symbols drifting downward.
141
+ * @param {string|HTMLElement} containerId
142
+ * @param {object} [options]
143
+ * @param {number} [options.density=0.15]
144
+ * @param {string[]} [options.symbols] – array of strings / emoji
145
+ * @param {boolean} [options.glow=true]
146
+ * @returns {number} session id
147
+ */
148
+ export function startLoveRain(containerId, options = {}) {
149
+ return _run(containerId, loveRain, options);
150
+ }
151
+
152
+ /**
153
+ * Colourful confetti raining down.
154
+ * @param {string|HTMLElement} containerId
155
+ * @param {object} [options]
156
+ * @param {number} [options.density=0.18]
157
+ * @param {string[]} [options.colors]
158
+ * @param {string[]} [options.shapes] – 'rect' | 'circle' | 'ribbon'
159
+ * @returns {number} session id
160
+ */
161
+ export function startConfetti(containerId, options = {}) {
162
+ return _run(containerId, confetti, options);
163
+ }
164
+
165
+ /**
166
+ * Fireworks that auto-launch on an interval.
167
+ * @param {string|HTMLElement} containerId
168
+ * @param {object} [options]
169
+ * @param {number} [options.interval=1200] – ms between launches
170
+ * @param {number} [options.particleCount=80]
171
+ * @param {boolean} [options.glow=true]
172
+ * @returns {number} session id
173
+ */
174
+ export function startFireworks(containerId, options = {}) {
175
+ return _run(containerId, fireworks, options);
9
176
  }
10
177
 
11
- export function startHeartTrail(containerId = 'body') {
12
- const canvas = initCanvas(containerId);
13
- heartTrail(canvas);
178
+ /**
179
+ * Drifting star field with optional constellation lines.
180
+ * @param {string|HTMLElement} containerId
181
+ * @param {object} [options]
182
+ * @param {number} [options.starCount=120]
183
+ * @param {number} [options.speed=0.4]
184
+ * @param {boolean} [options.twinkle=true]
185
+ * @param {number} [options.connectDist=100] – set to 0 to disable lines
186
+ * @returns {number} session id
187
+ */
188
+ export function startStarField(containerId, options = {}) {
189
+ return _run(containerId, starField, options);
14
190
  }
15
191
 
16
- export function startHeartBurst(containerId = 'body') {
17
- const canvas = initCanvas(containerId);
18
- heartBurst(canvas);
192
+ export function startButterflies(containerId, options = {}) {
193
+ return _run(containerId, butterflies, options);
19
194
  }
195
+
196
+ export function startMagicDust(containerId, options = {}) {
197
+ return _run(containerId, magicDust, options);
198
+ }
199
+
200
+ export function startFloatingOrbs(containerId, options = {}) {
201
+ return _run(containerId, floatingOrbs, options);
202
+ }
203
+
204
+ export function startShootingStars(containerId, options = {}) {
205
+ return _run(containerId, shootingStars, options);
206
+ }
207
+
208
+ // ─── Default export (convenient for UMD / CDN namespace) ──────────────────────
209
+ export default {
210
+ startFloatingHearts,
211
+ startHeartTrail,
212
+ startHeartBurst,
213
+ startSparkles,
214
+ startLoveRain,
215
+ startConfetti,
216
+ startFireworks,
217
+ startStarField,
218
+ startButterflies,
219
+ startMagicDust,
220
+ startFloatingOrbs,
221
+ startShootingStars,
222
+ stopAnimation,
223
+ stopAll,
224
+ };
package/gitignore DELETED
@@ -1,23 +0,0 @@
1
- # Ignore build output
2
- dist/
3
- node_modules/
4
- demo
5
-
6
- # Ignore Vite preview folder
7
- .vite/
8
-
9
- # Ignore logs
10
- npm-debug.log*
11
- yarn-debug.log*
12
- yarn-error.log*
13
-
14
- # Ignore environment files
15
- .env
16
- .env.*
17
-
18
- # Ignore IDE/editor files
19
- .vscode/
20
- .idea/
21
-
22
- # Ignore demo files (optional for npm publish)
23
- demo/
package/vite.config.js DELETED
@@ -1,15 +0,0 @@
1
- // vite.config.js
2
- import { defineConfig } from 'vite';
3
-
4
- export default defineConfig({
5
- build: {
6
- lib: {
7
- entry: 'src/index.js',
8
- name: 'RomanticAnimations', // this becomes window.RomanticAnimations
9
- fileName: 'romantic-animations',
10
- formats: ['umd']
11
- },
12
- outDir: 'dist',
13
- emptyOutDir: true
14
- }
15
- });